Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Entry from URL

Tags:

c#

asp.net

I am writing classic asp.net website and struggling with a problem.

Usually in URL send data by doing this: localhost/MyrandomPage.aspx?UserName=RandomUsername

But i am trying to make a page more personal so i want Url to look like this:

localhost.com/Profile/RandomUsername

And i am cant find a way how to retrive RandomUserName after slash in Url.

ive done Routing:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("",
            "/Pages/{UserName}",
            "~/Pages/Profile.aspx");
    }

But how do i retrive UserName??

like image 758
Timsen Avatar asked Jun 27 '26 19:06

Timsen


1 Answers

You should be able to get it using Page.RouteData.Values["UserName"] as string

Scott Gu has a good blog post covering routing in webforms.

like image 199
PHeiberg Avatar answered Jun 29 '26 18:06

PHeiberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!