RouteData.Values ​​stays empty

My route code looks like this:

 RouteTable.Routes.MapPageRoute("IDP", "Person/{IDP}", "~/Person.aspx")

And now I want to get the data in the form, usually it works as follows:

int id = Convert.ToInt32(Page.RouteData.Values["IDP"]);

But each time I try to get data from the route, for example: http://PC-81/SkillDatenbank/Person/1 I do not get data from the value (it is empty!)

I am using ASP.Net 4.5 with web forms. Edit: I created a new project and tested it, and it didn’t work. What am I doing wrong? in the last project he worked as follows :( Can you help me?

+4
source share
2 answers

Your problem is probably in your routing table. I created a WebForms project to test this.

Global.asax ( RouteConfig, - App_Start/RouteConfig.cs) RegisterRoutes. , .

void RegisterRoutes(RouteCollection routes)
{
    var settings = new FriendlyUrlSettings();
    settings.AutoRedirectMode = RedirectMode.Permanent;
    routes.EnableFriendlyUrls(settings);

    /* ... additional routes */
    routes.MapPageRoute("","Person/{IDP}", "~/Person.aspx");
}

Application_Start , , App_Start: RouteConfig.RegisterRoutes(RouteTable.Routes);

global.asax.cs, RegisterRoutes(RouteTable.Routes);

http://PC-81/SkillDatenbank/Person/1, RouteData 1 , :

enter image description here

+3

, .

, RedirectMode , JQuery inorder, Webmethod, RedirectMode.

void RegisterRoutes(RouteCollection routes)
{
     /* ... additional routes */
    routes.MapPageRoute("","Person/{IDP}", "~/Person.aspx");

    var settings = new FriendlyUrlSettings();
    settings.AutoRedirectMode = RedirectMode.Permanent;
    routes.EnableFriendlyUrls(settings);

}
+3

Source: https://habr.com/ru/post/1547592/


All Articles