get current page from url

amateur picture amateur · Jan 28, 2011 · Viewed 106.7k times · Source

I want to write a c# method to retrieve the current page. eg Default6.aspx I know I can do the following:

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx

string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx

string host = HttpContext.Current.Request.Url.Host;
// localhost

but how can I get Default6.aspx? And if the url is http://localhost:1302/TESTERS/, my method should return default.aspx

Answer

Paul Alexander picture Paul Alexander · Jan 28, 2011
Path.GetFileName( Request.Url.AbsolutePath )