Web applications often need to reference absolute paths, such as to retrieve images or Xml files. Fortunately, ASP.Net provides many ways to do this using the HttpRequest class. In code-behind pages this can be referenced as a property of the page like:
For pages that aren't code-behinds, you can reference it through the current HttpContext like:
Given the following scenario, the table below shows the values for different types of paths.
- ASP.Net application "Learning_VB", which resides on localhost (located at C:\Inetpub\wwwroot).
- An aspx page, urltest, which is in the url/subfolder folder of the application
- A querystring "id=5&name=Tim"
The different types of paths have several differentiators:
- Is it physical or virtual (note that web addresses use '/', and physical use '\') ?
- Does it include the querystring?
- Does it include the the full path or just start at the project folder Learning_VB)?
You can make your own version of this chart by simply creating a table on a WebForm, and then writing out the Path Type to the appropriate cell like so (note the code below is in VB, not C#):
I've found this a very useful chart for sorting out the different path types.
Post a Comment