You should be able to do something like this:
routes.MapRoute(
"CatchAll",
"{action}/{*path}",
new { controller = "MyController", action = "Index" }
);
Essentially you're telling it all requests should treat the path as the Action and they should all go to "MyController". The action = "Index" acts as a default in the event that an Action is not provided in the Url.
The above route definition will evaluate to true even if extra, invalid path data is appended after the action name. What that means is that both /Action1
and /Action1/251958125ad/2512qsadfa2
will go to Action1()
. If you would prefer that only the exact path be allowed:
routes.MapRoute(
"CatchAll",
"{action}",
new { controller = "MyController", action = "Index" }
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…