ASP.NET MVC4 以 webforms Default.aspx 作为起始页 [英] ASP.NET MVC4 with webforms Default.aspx as the start page

查看:29
本文介绍了ASP.NET MVC4 以 webforms Default.aspx 作为起始页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET MVC4 应用程序,在 Global.asax.cs 中定义了以下路由.应用程序的起始页是从 Home 控制器的操作方法 Index() 返回的 Index.cshtml 视图.然后,我添加了一个以 Default.aspx 作为起始页的旧版 ASP.NET WebForms 应用程序.如何将此 Default.aspx 页面作为此集成 MVC+WebForms 应用程序的起始页面:

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


        }

推荐答案

在您的 Global.asax 中尝试以下操作:

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

此外,我认为您不需要 Default 路由的 .mvc 部分.

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

这篇关于ASP.NET MVC4 以 webforms Default.aspx 作为起始页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆