tags:

views:

432

answers:

3

I am using IIS 6. I think my problem is that I don't know how to route to a non controller using the routes.MapRoute.

I have a url such as example.com and I want it to serve the index.htm page and not use the MVC. how do I set that up? In IIS, I have index.htm as my start document and my global.asax has the standard "default" routing, where it calls the Home/Index.

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

I added this:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Context.Request.FilePath == "/") Context.RewritePath("index.htm");
    }

it works. But is this the best solution?

A: 

routes.IgnoreRoute ?

Also, see this question: http://stackoverflow.com/questions/273447/how-to-ignore-route-in-aspnet-forms-url-routing

chakrit
I added this:routes.Add(new Route("{resource}.htm/{*pathInfo}", new StopRoutingHandler()));It didn't work.added this: routes.IgnoreRoute("{resource}.htm/{*pathInfo}"); didn't work either
Marsharks
What order did you add it in? I think it matters that the StopRoutingHandler route would be the first in the list.
Nick DeVore
I added it before the routes.Add Now I have a problem with the asp pages not loading!
Marsharks
I mean, I added it before the routes.MapRoute
Marsharks
Try routes.Ignore("index.htm/{*pathInfo}");
Neal
A: 

I added a dummy controller to use as the default controller when the root of the web site is specified. This controller has a single index action that does a redirect to the index.htm site at the root.

public class DocumentationController : Controller
{
    public ActionResult Index()
    {
        return Redirect( Url.Content( "~/index.htm" ) );
    }

}

Note that I'm using this a the documentation of an MVC-based REST web service. If you go to the root of the site, you get the documentation of the service instead of some default web service method.

tvanfosson
A: 

IIS6 has a few differences from IIS7 in how ASP.NET works with it. Check out this blog post from Phli Haack on how to get this set up to use with ASP.NET MVC. Good luck!

J.R. Garcia