问题
I am looking for a way to route all traffic to my Home controller and to the Index action, regardless of the URL they use to arrive at my site.
As long as they are using www.MyDomain.com, a user visiting www.MyDomain.com/Controller1/Action1 would need to all be routed to the same action as a user visiting www.MyDomain.com/Controller2/Action3/ID6
I can redirect each one of these manually but some of the URL's may be dynamically generated and therefore I need to learn how to catch all and redirect.
Many thanks for reading.
回答1:
When setting your routes, you may try defining a default route as the last route definition
routes.MapRoute(
"Default",
"{*any}",
new { controller = "Home", action = "Index" }
);
Hope this will help
回答2:
There exists a file Global.asax.cs
in root of your solution where logic for routing is written, modify the logic according to your requirement.
来源:https://stackoverflow.com/questions/14585519/how-could-i-route-to-the-home-index-action-regardless-of-the-url