Home > ASP.Net > Get Page Name from URL

Get Page Name from URL


Hi all,

try this example to Get Page Name from URL

protected void Page_Load(object sender, EventArgs e)
{
        string url = Request.Url.AbsolutePath.ToString();
        string[] splitUrl1 = url.Split('/');
        string pagename = splitUrl1[splitUrl1.Length - 1].ToString();
        if (pagename == "Test.aspx")
        {
            //do something
        }
}

and there is another way to get Page Name

string[] pagename_aspx = Page.GetType().Name.ToLower().Split(new char[] { '_' });
string PageName = pagename_aspx[pagename_aspx.Length - 2];

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net
  1. December 20, 2010 at 11:18 pm

    “”
    What I can not believe!

  2. May 13, 2011 at 3:01 am

    thanks. i need this for my blog.

  3. yasserzaid
    May 14, 2011 at 6:10 am

    @apron sale , @buijobtheo :- You are Welcome hope my post helps you

  4. September 14, 2012 at 9:58 am

    Hi everyone, it’s my first visit at this web site, and piece of writing is genuinely fruitful designed for me, keep up posting these types of posts.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: