Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name of virtual directory?

I'm using Request.ApplicationPath to learn the name of the Virtual Directory in which I'm running. Is there a more reliable way?

like image 516
lance Avatar asked Jan 30 '10 18:01

lance


2 Answers

Request.ApplicationPath is perfectly reliable way of getting the virtual directory and works always when you have the HttpContext and can ask for the Request data.

For further processing and extracting parts of the path, take a look at the VirtualPathUtility class.

like image 88
Tomas Vana Avatar answered Nov 01 '22 18:11

Tomas Vana


You need to use Request.ApplicationPath. That is what it is designed for.

Editing to go with your comment.

Since you want a 'cleaner' way to handle the slash, I recommend creating a utility function that returns the application path with the logic in it to deal with the slash as you see fit.

like image 37
Clarence Klopfstein Avatar answered Nov 01 '22 16:11

Clarence Klopfstein