C# – Set “Homepage” in Asp.Net MVC

asp.net-mvcasp.net-mvc-routingc

In asp.net MVC the "homepage" (ie the route that displays when hitting www.foo.com) is set to Home/Index .

  • Where is this value stored?
  • How can I change the "homepage"?
  • Is there anything more elegant than using RedirectToRoute() in the Index action of the home controller?

I tried grepping for Home/Index in my project and couldn't find a reference, nor could I see anything in IIS (6). I looked at the default.aspx page in the root, but that didn't seem to do anything relevent.

Thanks

Best Answer

Look at the Default.aspx/Default.aspx.cs and the Global.asax.cs

You can set up a default route:

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

Just change the Controller/Action names to your desired default. That should be the last route in the Routing Table.