문제

What is the difference between results of

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

and

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{*id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

What does "*" do, other than without it.

도움이 되었습니까?

해결책

Marking id with an asterisk will flag it as a "catch-all" parameter, e.g.

/Content/List/1 --> id = "1"

/Content/List/My/Content --> id = "My/Content"

However, with the following route: "{controller}/{action}/{id}" the second URL would not match at all.

More information on catch-all parameters on MSDN:

To handle additional segments in this manner you mark the last parameter with an asterisk (*). This is referred to as a catch-all parameter. A route with a catch-all parameter will also match URLs that do not contain any values for the last parameter. The following example shows a route pattern that matches an unknown number of segments. query/{queryname}/{*queryvalues}

다른 팁

here is a similar question. the second one is just cause it to cached with the Catchall mapping.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top