Karl Humphries
Karl Humphries

Reputation: 328

How could I route to the /Home/Index action regardless of the URL?

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.

Upvotes: 0

Views: 344

Answers (2)

jbl
jbl

Reputation: 15413

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

Upvotes: 3

Ankit
Ankit

Reputation: 690

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.

Upvotes: 2

Related Questions