- Use the tilde character – "~" – in server controls and code, since it parses this out to mean "this application’s root URL". Don’t try to use this in JS or other client-side stuff, though.
- HttpRequest.ApplicationPath provides this same info, but is less declarative and more clutter
- HttpRequest.CurrentExecutionFilePath gives you the app root, any folders and the executing page. This is true even after a Server.Transfer or a Server.Execute.
- HttpRequest.FilePath is similar, but gives the original (calling) page after Server.Transfer or a Server.Execute.
- HttpRequest.Path returns the current URL path, exluding the host (and related kit). This also includes any "trailers" after the page, like …/default.aspx/blah/blah/blah
- HttpRequest.PhysicalApplicationPath is the root path on the disk of the server where the application lives – corresponding to ApplicationPath. Don’t send this to the client.
- HttpRequest.PhysicalPath is the physical path of the currently executing page.
Filed under: .Net Basics