欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET Core MVC配置差异(3.0和2.X)

程序员文章站 2022-07-02 12:22:38
https://www.cnblogs.com/lonelyxmas/p/10934388.html net core 2.x MVC配置 public void ConfigureServices(IServiceCollection services) { services.addMvc(); ......

net core 2.x mvc配置

        public void configureservices(iservicecollection services)
        {
            services.addmvc();
        }

 

        public void configure(iapplicationbuilder app, iwebhostenvironment env,iconfiguration configurarion,iwelcome welcome)
        {
            if (env.isdevelopment())
            {
                app.usedeveloperexceptionpage();
            }

            app.userouting();
            app.usestaticfiles();

            app.usemvc(routs =>
            {
                routs.maproute("default", "{controller=home}/{action=index}/{id?}");
            });
        }

net core 3.x mvc配置

        public void configureservices(iservicecollection services)
        {
            services.addcontrollerswithviews();
        }

 

        public void configure(iapplicationbuilder app, iwebhostenvironment env,iconfiguration configurarion,iwelcome welcome)
        {
            if (env.isdevelopment())
            {
                app.usedeveloperexceptionpage();
            }

            app.userouting();
            app.usestaticfiles();

            app.useendpoints(endpoints =>
            {
                endpoints.mapcontrollerroute("default", "{controller=home}/{action=index}/{id?}");
            });
        }