How to get virtual directory in mvc

3.5k views Asked by At

I am working on a .net core application where I need the application path to the virtual directory. I do not want the physical path, I want it in form of url like:

http://www.mywebsite.com/mydirectory

I have tried with Request.Host but it only gives me http://www.mywebsite.com without the virtual directory path.

Any help on this appreciated!

1

There are 1 answers

0
Matze On BEST ANSWER

You can use the IUrlHelper to resolve the base-path of the application. If the application is not hosted within a virtual directory the returned path is just empty...

IUrlHelper url = ...
string virtualDirectory = url.Content("~");