Search code examples
c#asp.net.netrazorwebmatrix

Getting name of Page being requested/was requested


I know this is easy, but I've forgotten how and since I can't remember what it's called; it's been difficult trying to search for a solution.

How can we request the page name in C#?

E.g.:

String pageName = String.Empty;
if(IsPost)
{
   pageName = Request.PageName; // example only
}

Solution

  • To make the answer cleaner

    public string GetPageName() 
    { 
        string path = System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
        System.IO.FileInfo info = new System.IO.FileInfo(path); 
        return info.Name; 
    }