It seems to be a very common practice to check the URL and File paths. Many, Many
scenarios require this information, and it seems that a lot of native classes are
commonly overlooked. To bring awareness to classes that you may or may not know
exist, I've thrown together a little table that shows several ways to get path information.
The code is in black, and the result is in red.
Syntax to Request Path Information: Result
Request.ApplicationPath Returns: /MyWebSite
Request.CurrentExecutionFilePath:
/MyWebSite/Paths/Paths.aspx
Request.FilePath: /MyWebSite/Paths/Paths.aspx
Request.PhysicalApplicationPath: c:\inetpub\wwwRoot\MyWebSite\
Request.Physicalpath: c:\inetpub\wwwRoot\MyWebSite\Path\Paths.aspx
Request.MapPath("/"): c:\inetpub\wwwRoot\
Request.RawUrl: /MyWebSite/Paths/Paths.aspx
System.IO.Path.GetFileNameWithoutExtension(Request.PhysicalPath):
filename
System.IO.Path.GetExtension(Request.PhysicalPath): .aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath):
c:\inetpub\wwwRoot\MyWebSite\Path
Feedback is welcome for mistakes, typos, and additional path informaiton.
Enjoy!!