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

I had an ASP.NET MVC4 application with the following routing defined in Global.asax.cs. The application start page is an index.cshtml view that is returned from the Index () action method of the main controller. Then I added an outdated ASP.NET WebForms application in which the start page had Default.aspx. How can I make this Default.aspx page the start page of this embedded MVC + WebForms application:

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 = "" }
            );


        }
+4
source share
1 answer

Try the following in the Global.asax file:

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
    );
}

, .mvc Default.

+16

Source: https://habr.com/ru/post/1527241/


All Articles