Retrieve ASP.NET Page Name

In ASP.NET you can get the page name using the HttpRequest object. Look at the following 2 examples and you can easily convert it from C# to VB, PHP, PERL or whatever.

This will include the relative path to the form.

This only includes the name of the page or form.

This is helpful if you are using master pages with content pages as you may need to know what you page you are showing on the master page.

0 thoughts on “Retrieve ASP.NET Page Name”

  1. Shouldn’t this read: Request.Path.Substring(Request.ApplicationPath.Length+0);

    Instead of:Request.Path.Substring(Request.ApplicationPath.Length+1);

  2. No,

    jasongeiger’s code is correct. Using Length+1 provides the page name without a leading backslash. This is more useful in many cases.

Leave a Reply

Your email address will not be published. Required fields are marked *

× six = 54

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>