Search code examples
asp.net-mvcasp.net-mvc-4webformsasp.net-mvc-routing

ASP.NET MVC4 with webforms Default.aspx as the start page


I had an ASP.NET MVC4 app with the following routing defined in the Global.asax.cs. The app's start page is Index.cshtml view that is returned from the action method Index() of the Home controller. I then added a legacy ASP.NET WebForms app that had Default.aspx as the start page. How can I make this Default.aspx page as the start page of this integrated MVC+WebForms app:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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


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


        }

Solution

  • Try the following in your Global.asax:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        // Web Forms default
        routes.MapPageRoute(
            "WebFormDefault",
            "",
            "~/default.aspx"
        );
    
        // MVC default
        routes.MapRoute(
            "Default",                          // Route name
            "{controller}/{action}/{id}",       // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }  // parameter default
        );
    }
    

    Also I don't think you'll need the .mvc portion of the Default route.