Getting current page name from complete webpage url

In asp.net once a requirement comes to me to get the current web page name from complete web page url. I have done it using C# code behind and now I want to share my experience with you.

protected void Page_Load(object sender, EventArgs e)

{
string str = Request.RawUrl;
int n = str.LastIndexOf('/');
string pagename = str.Substring(n + 1, str.Length - n - 1);
lbl_Pagename.Text= pagename;
}

So this is the way to get the current web page name from complete web page url in C# code behind.

0 comments: