从2.1到2.2的ASP.NET Core 2.2升级路由

时间:2018-12-13 09:43:52

标签: asp.net-core-2.2

我正在将我的应用程序从ASP.NET Core 2.1升级到2.2。我遇到问题的路由发生了变化。我已经检查了以下链接的来源。

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2

https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/

这是我在Startup.cs中的Core 2.1代码

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            //Area Marketing
            routes.MapRoute(name: "Marketing",
            template: "Marketing/{controller}/{action}/{id?}");

            //Area Media
            routes.MapRoute(name: "Media",
            template: "Media/{controller}/{action}/{id?}");

            //Area Membership
            routes.MapRoute(name: "Membership",
            template: "Membership/{controller}/{action}/{id?}");

            //Area Military
            routes.MapRoute(name: "Military",
            template: "Military/{controller}/{action}/{id?}");


            //Area Process
            routes.MapRoute(name: "Process",
            template: "Process/{controller}/{action}/{id?}");
        });

这是我迁移的Startup.cs中的Core 2.2代码。

        //ASP.NET Core 2.2 Routes
        var routes = new RouteBuilder(app);
        //
        //routes.DefaultHandler = new MvcRouteHandler(???);
        //
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");

        //Area Marketing
        routes.MapRoute(name: "Marketing",
        template: "Marketing/{controller}/{action}/{id?}");

        //Area Media
        routes.MapRoute(name: "Media",
        template: "Media/{controller}/{action}/{id?}");

        //Area Membership
        routes.MapRoute(name: "Membership",
        template: "Membership/{controller}/{action}/{id?}");

        //Area Military
        routes.MapRoute(name: "Military",
        template: "Military/{controller}/{action}/{id?}");


        //Area Process
        routes.MapRoute(name: "Process",
        template: "Process/{controller}/{action}/{id?}");
        app.UseRouter(routes.Build());
    }

运行应用程序时,出现以下错误: enter image description here

看来我需要为此创建或设置处理程序。我的Handler代码看起来像什么,因为找不到任何示例或教程。

0 个答案:

没有答案