Login

Determine path to the current page

Versions: n/a, FAQ number: 32, Old FAQ number: 967

Q: How do i get the path to the current page?

A: The following code gives you the path to the current page.

System.Web.HttpRequest httpRequest = System.Web.HttpContext.Current.Request;
string fileRelativePath = httpRequest.Url.AbsolutePath;
 
if (httpRequest.ApplicationPath.Length > 1)
 fileRelativePath = fileRelativePath.Substring(httpRequest.ApplicationPath.Length);

fileRelativePath = fileRelativePath.Substring(0, fileRelativePath.LastIndexOf('.')).ToLower();

EPiTrace logger