Asp.net mvc is usually
Address form ofcontroller/action/parameters
But most of the time, the website address is not such a path
like:
xxxx.com/asp.net/
xxxx.com/asp.net/mvc/
xxxx.com/asp.net/webform/
xxxx.com/asp.net/ado.net/
xxxx.com/javascript/
xxxx.com/javascript/jquery/
xxxx.com/javascript/angularjs/
xxxx.com/javascript/jichu/
xxxx.com/jiaoyu/
At this time, the address is not in the form of controller/action/parameter
I don’t know how to map this kind of path in asp.net mvc? ? ?
阿神2017-05-16 17:08:19
This depends on how your routing rules are defined and the order in which the routes are defined.
If this request enters the ASP.NET pipeline model, it will go to the predefined route to perform matching. When it encounters the first matching route, it will directly return the routing result.
For example, the first routing rule of the default route is:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Admin", action = "Login", id = UrlParameter.Optional }
);
xxxx.com/asp.net/ will match this routing rule, controller="asp.net", action="Login";
xxxx.com/asp.net/mvc/ will also match this routing rule, controller="asp.net", action="mvc";
Suppose you define another routing rule, and this routing rule is in front of the routing rule just now:
routes.MapRoute(
name: "asp.net",
url: "asp.net/{controller}/{action}/{id}",
defaults: new { controller = "User", action = "Link", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Admin", action = "Login", id = UrlParameter.Optional }
);
xxxx.com/asp.net/ will match this routing rule, controller="User", action="Link";
However, xxxx.com/cast/ will not match the first routing rule, but will continue to match with the second routing rule. At this time, the match will be successful, controller="cast", action="Login"
It is recommended that you read the book "Mastering the ASP.NET MVC3 Framework". Chapter 11 Routing Rules provides an analysis and introduction to this issue.