MVC2 without Routing
-
26-09-2019 - |
문제
I have a case where MVC's routing (mapping a url to a controller) is just getting in the way. I want to circumvent it and send all urls to a single controller (no matter the format and without any attempt to parse them).
I assumed this would be easy, but I'm stuck. Help is much appreciated.
해결책
Write a catch-all route (global.asax) and define a default action/controller to this route..
routes.MapRoute(
"All",
"{*all}",
new { controller = "Home", action = "Index" }
);
다른 팁
Adding this to Application_Start
in Global.asax.cs should work:
RouteTable.Routes.MapRoute(null, "{*path}", new { controller = "MyController", action = "MyAction" });
The parameter to MyAction
should be called path
.
제휴하지 않습니다 StackOverflow