我用的也是2.2,出現(xiàn)異常!
System.InvalidOperationException
? HResult=0x80131509
? Message=Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.
? Source=Microsoft.AspNetCore.Mvc.Core
? StackTrace:
? ?at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.VerifyMvcIsRegistered(IApplicationBuilder app)
? ?at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
? ?at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvcWithDefaultRoute(IApplicationBuilder app)
? ?at Lanzhoulamian.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\Users\Administrator\Desktop\Lanzhoulamian\Lanzhoulamian\Startup.cs:line 27
2020-04-15
?很強的學習能力!
2020-05-17
services.AddMvc(options => options.EnableEndpointRouting = false),添加這條確實可以解決該問題,謝謝!
2020-04-12
通過查找百度找到問題了!
在ASP.NET Core 2.2中,新增了一種路由,叫做
Endpoint
(終結點)路由。本文將以往的路由系統(tǒng)稱為傳統(tǒng)路由
。本文通過源碼的方式介紹傳統(tǒng)路由和
Endpoint
路由部分核心功能和實現(xiàn)方法,具體功能上的差異見官方文檔。在升級到ASP.NET Core 2.2后,會自動啟用
Endpoint
路由? ? ? public void ConfigureServices(IServiceCollection services)
? ? ? ? {
????????????//添加
? ? ? ? ? ? services.AddMvc(options => options.EnableEndpointRouting = false)
? ? .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
? ? ? ? }