Cyril Gupta
Cyril Gupta

Reputation: 13723

How can I set up a Default Controller Route (When Controller name is not provided)?

I want to have URLs like below in my ASP.Net website:

http://mysite/about http://mysite/faq http://mysite/bla

I don't want to have a controller each for them. Is there any way I can set up a default controller scheme so that if a controller with a suitable name is not found, it will hit the default controller.

Or is there an in-built feature in ASP.Net MVC which does this that I am not aware of.

Upvotes: 1

Views: 92

Answers (1)

Cyril Gupta
Cyril Gupta

Reputation: 13723

Forgive me for jumping the gun. With a little trial it was too easy:

   //General
    routes.MapRoute(
        "Default7",                                              // Route name
        "{action}/",                           // URL with parameters
        new { controller = "Home", action = "Index" }  // Parameter defaults
    );

Now http://mysite/about will point to the Home->About controller action

Upvotes: 2

Related Questions