Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc'...'
.Net Core 更新太快了,上一个版本用 useMVC()
或 app.UseMvcWithDefaultRoute()
用的好好的,下一个版本就废了。这不,添加了两行
useMVC() app.UseMvcWithDefaultRoute()
就暴了下面的错误
Message "Endpoint Routing does not support 'IApplicationBuilder.UseMvc(...)'. To use 'IApplicationBuilder.UseMvc' set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices(...)." string
和下面两个警告
Startup.cs(13,13): Warning MVC1005: Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'. (MVC1005) (Demo)
Startup.cs(13,13): Warning MVC1005: Using 'UseMvcWithDefaultRoute' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvcWithDefaultRoute', please set 'MvcOptions.EnableEndpointRouting = false' inside 'ConfigureServices'. (MVC1005) (Demo)
出现这个问题的原因, 是 Asp.Net Core 3.0中默认不再支持app.UserMvc() 方式配置路由系统。
解决方法也简单,就是将
services.AddMvc();
改成
services.AddMvc(options => { options.EnableEndpointRouting = false; });
当然了,这不是推荐的做法,因为这么做会把 EndpointRouting
给干掉。
更推荐的做法就是
app.UseEndpoints(endpoints => { // 添加默认的路由控制器 endpoints.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}"); });
目前尚无回复