Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the complete virtual path of an ASP.NET application

How do I know the the complete virtual path that my application is currently hosted? For example:

http://www.mysite.com/myApp 

or

http://www.mysite.com/myApp/mySubApp 

I know the application path of HttpRequest but it only returns the folder name that my application is currently hosted, but how do I get the initial part?

like image 271
user115195 Avatar asked May 31 '09 20:05

user115195


People also ask

Where is virtual directory path in asp net?

Go to Websites & Domains and find the website's domain name. Click Virtual Directories. Browse to the required directory and click a link with its name. Click ASP.NET Settings.

What is virtual path in asp net?

The virtual path of a web folder is (almost) never the same as the physical folder. In your code you will, reference both the physical path and the virtual path, depending on what you are coding. ASP.NET has 3 tools for working with folder paths: the ~ operator, the Server. MapPath method, and the Href method.

What is a virtual file path?

Virtual paths are virtual file system paths that map to a physical path on your domain and have their own set of permissions. This allows you to have complete control over what resources users may access on your domain without having to manage users and permissions at the OS level.

What is virtual path and physical path?

Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder. Let's display this image from Hard-drive 'E' using a virtual directory in IIS Default web site.


2 Answers

The domain name part of the path is not really a property of the application itself, but depends on the requesting URL. You might be able to reach a single Web site from many different host names. To get the domain name associated with the current request, along with the virtual path of the current application, you could do:

Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath 

Technically, an "application" is a virtual directory defined in IIS and Request.ApplicationPath returns exactly that. If you want to get the folder in which the current request is handled, you can do this:

VirtualPathUtility.GetDirectory(Request.Path) 

ASP.NET has no idea how to distinguish your sub-application from a bigger application if it's not defined as a virtual directory in IIS. Without registering in IIS, it just sees the whole thing as a single app.

like image 114
mmx Avatar answered Sep 20 '22 14:09

mmx


Request.Url 

it contains several points that you might consider to use, see the image below:

enter image description here

like image 29
balexandre Avatar answered Sep 22 '22 14:09

balexandre