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

问题描述

我曾与在Global.asax.cs中定义的下列路由的ASP.NET应用程序MVC4。该应用程序的启动页面是从主控制器的操作方法指数()返回Index.cshtml视图。然后我加了一个传统的ASP.NET的WebForms应用程序,有Default.aspx的作为起始页。我怎样才能使这个Default.aspx页面为这种集成MVC +的WebForms应用程序的开始页面:

 公共静态无效的RegisterRoutes(RouteCollection路线)
        {
            routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);            routes.MapRoute(
                默认,
                {}控制器.mvc / {}动作/(编号),
                新{行动=索引,ID =}
              );
              routes.MapRoute(
              根,
              ,
              新{控制器=家,行动=索引,ID =}
            );
        }


解决方案

尝试在Global.asax中以下内容:

 公共静态无效的RegisterRoutes(RouteCollection路线)
{
    routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);    // Web窗体默认
    routes.MapPageRoute(
        WebFormDefault
        ,
        〜/ Default.aspx的
    );    //默认MVC
    routes.MapRoute(
        默认,//路线名称
        {控制器} / {行动} / {ID},// URL带参数
        新{控制器=家,行动=索引,ID = UrlParameter.Optional} //默认参数
    );
}

此外,我不认为你需要在默认路由 .mvc 部分。

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


        }
解决方案

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.

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

07-31 11:03