Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The default document (default.aspx) in IIS is not working after adding MVC and routing to a WebForms project

I have an existing ASP.NET 3.5 WebForms project and have added ASP.NET MVC to the project. The existing pages work fine and so do the new controllers & views. However, when I deploy to IIS 7 the default document (default.aspx) is no longer working. I can get to it if I type it in explicitly but 'xyz.com' doesn't work - I get a 404. In contrast, it does work fine in Cassini.

How do I get the default document working again while still retaining the new MVC stuff.

like image 532
John Mills Avatar asked Sep 28 '11 01:09

John Mills


1 Answers

I added the following to the Global.asx.cs file and the default document works again.

    public static void RegisterRoutes(RouteCollection routes)
    {
        // *** This Line ***
        routes.IgnoreRoute("");                                     // Required for the default document in IIS to work
        // *****************
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

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

    protected void Application_Start(Object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }
like image 58
John Mills Avatar answered Sep 28 '22 01:09

John Mills