我有一个 ASP.NET MVC4 应用程序,在 Global.asax.cs 中定义了以下路由。应用程序的起始页是从 Home Controller 的操作方法 Index() 返回的 Index.cshtml View 。然后,我添加了一个以 Default.aspx 作为起始页的旧版 ASP.NET WebForms 应用程序。如何将此 Default.aspx 页面作为此集成 MVC+WebForms 应用程序的起始页:
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 = "" }
);
}
最佳答案
在 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
);
}
此外,我认为您不需要 Default
路由的 .mvc
部分。
关于asp.net-mvc - 以 Webforms Default.aspx 作为起始页的 ASP.NET MVC4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21819051/