从Page对象中获取PageName.aspx

Pos*_*Guy 3 asp.net

我想从当前页面对象获取pagename.aspx.我希望通过HttpContext.Current做到这一点.请求,因为如果我已经在页面上做某事,为什么不从页面抓取它...我不需要担心这里的任何上下文.

我猜页面已经有了名称,我只需要附加.aspx,但有没有办法自动获取扩展名?

Lar*_*nal 6

public string GetCurrentPageName() 
{ 
    string sPath = Request.Url.AbsolutePath;
    System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
    string sRet = oInfo.Name; 
    return sRet; 
} 
Run Code Online (Sandbox Code Playgroud)

(改编自http://www.aspcode.net/Get-current-page-name.aspx)