The default document (default.aspx) in IIS does not work after adding MVC and routing to the WebForms project

I have an existing ASP.NET 3.5 WebForms project and have added ASP.NET MVC to the project. Existing pages work fine, as well as new controllers and views. However, when deployed to IIS 7, the default document (default.aspx) no longer works. I can get to it if I type it explicitly, but "xyz.com" does not work. I get 404. On the contrary, it works fine in Cassini.

How to get a default document that works again while maintaining new MVC content.

+5
source share
2 answers

I added the following to the file Global.asx.csand 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);
    }
+9
source

Do you have default documents for your IIS application and default.aspxon the list? Just double check them, I can’t think of anything else that would affect the maintenance of the default.aspx page. IIS should look something like this:

IIS Default Document

0
source

All Articles