Question

I know this site is written using ASP.Net MVC and I do not see "/Home" in the url. This proves to me that it can be done. What special route and do I need?

Was it helpful?

Solution

Just change "Home" to an empty string.

routes.MapRoute(
    "Home",
    "",
    new { action = Index, controller = Home }
);

OTHER TIPS

If you're running on IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1. For more details check out:

http://haacked.com/archive/2008/04/10/upcoming-changes-in-routing.aspx and http://haacked.com/archive/2008/05/12/sp1-beta-and-its-effect-on-mvc.aspx

I actually like having all of my home controller methods to be at the root of the site. Like this: /about, /contact, etc. I guess I'm picky. I use a simple route constraint to do it. Here is my blog post with a code sample.

I'd add

routes.MapRoute("NoIndex", "{action}", new { controller = "Home", action = "Index" });

in RouteConfig.cs

This is what I did to get rid of Home. It will treat all routes with only one specifier as Home/Action and any with two as Controller/Action. The downside is now controller has to have an explicit index (/Controller != /Controller/Index), but it might help you or others.

routes.MapRoute(
    "Default",
    "{action}",
    new { controller = "Home", action = "Index" }
);

routes.MapRoute(
    "Actions",
    "{controller}/{action}",
    new { }
);

In IIS 7, you can simply delete the Default.aspx file that comes with ASP.NET MVC (assuming you're running on Preview 3 or higher). That file was needed due to an issue with Cassini that was fixed in .NET 3.5 SP1.

For more details check out:

Upcoming Changes In Routing and .NET 3.5 SP1 Beta and Its Effect on MVC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top