.net core2.1 迁移.net core 3.1

1.解决方案->属性-->目标框架 .net core3.1

2.删除旧的Nuget包添加新的NuGet包

3.修改Startup.cs

  • 修改ConfigureServices
  • 修改Configure

Configure源码

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Shared/Error");
            }
            app.UseHttpsRedirection();

            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                //endpoints.MapDefaultControllerRoute()
                //.RequireAuthorization();
                endpoints.MapRazorPages();
                // endpoints.MapControllers();
                //      endpoints.MapAreaControllerRoute(
                //"admin",
                //"admin",
                //"Admin/{controller=Home}/{action=Index}/{id?}");//为路由创建区域 对应控制器Controller头加Area和Route标签 非必须设置
                endpoints.MapControllerRoute(
          "default", "{controller=Home}/{action=Index}/{id?}");//添加控制路由
            });

        }

4.修改Program.cs

  • Host替换Webhost

Program.cs源码

public static void Main(string[] args)
        {
            CreatHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreatHostBuilder(string[] arges) =>
            Host.CreateDefaultBuilder(arges)
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
posted @ 2020-11-18 13:33  C余L小R鱼  阅读(275)  评论(0编辑  收藏  举报