Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get virtual directory in mvc

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!

like image 861
XamDev Avatar asked Dec 22 '25 00:12

XamDev


1 Answers

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("~");
like image 199
Matze Avatar answered Dec 28 '25 08:12

Matze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!