【问题标题】:Routing in a hybrid app that is classic ASP.Net web forms and MVC经典 ASP.Net Web 表单和 MVC 混合应用程序中的路由
【发布时间】:2014-03-17 15:26:49
【问题描述】:

我继承了一个既是经典的 asp.net Web 表单又是 mvc 的应用程序(作为 Web 表单项目开始)。我想像 MVC 一样设置路由。去这里的最佳方式是什么? 我所需要的只是朝着正确的方向前进。

我知道如何通过 global.asa > App_Start > Route Config 和区域注册 cs 文件为仅 MVC 项目设置路由。

环境:

VS 2012、IIS 7、ASP.NET 4.0、经典的 asp.net Web 表单和 MVC 4。

我的想法:

我正在考虑做一些类似以下的事情,你们看到这里有问题吗?我最终可能会遇到一些 web.config 问题,但此时我不确定那些会是什么。 我需要您的建议才能在此处正确设置结构。

全局文件添加:

protected void Application_Start()
        {

            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }

App_Start > RouteConfig.cs

    namespace My.Site
    {
        public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                    namespaces: new string[] { "My.Site.Controllers" }
                );

OTHER ROUTES WILL GO HERE, THESE MAY REDIRECT TO a webform page or to a controller action. 

            }




        }
    }

【问题讨论】:

标签: asp.net .net asp.net-mvc-4 routing


【解决方案1】:
猜你喜欢
  • 2018-08-07
  • 1970-01-01
  • 2010-12-07
  • 2016-04-26
  • 1970-01-01
  • 1970-01-01
  • 2012-10-25
  • 1970-01-01
  • 2014-02-25
相关资源
最近更新 更多