简体   繁体   中英

Get Entry from URL

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??

假设您的路由方案正确且一切正常,您可以从请求上下文中获取路由值(在本例中为“action”):

string userName = (string) requestContext.RouteData.Values["UserName"]; 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM