升级“ DependencyInjection”后的C#身份验证问题

时间:2020-03-07 10:09:20

标签: c# authentication .net-core

我正在研究一个将.NET Core 2.1和.NET Core 3.1都用于项目的解决方案。我最近不得不将Microsoft.Extensions.DependencyInjection从2.2.0升级到3.0.0版本。但是,现在每当我尝试访问端点时都会遇到运行时错误:

System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider' has been registered.
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

现在,当我在线搜索时,除了Microsoft文档和GitHub帖子中提到的定义(分别简单地说应该provide the AuthenticationHandlerresponsible for returning the correct handler instance for a given scheme and request.)外,我找不到其他东西

它显然在AuthenticationMiddleware类的Invoke调用上中断了,但是我相信我读到某个地方,您不应轻易创建自己的authenticationMiddleware,并且该类应“开箱即用”地工作,所以我不太喜欢确定如何解决此问题。

恐怕我对认证的经验不是很丰富,所以我不确定发现问题所需的代码。如果有任何重要遗漏,请发表评论,我将其添加。任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

我正在研究一个将.NET Core 2.1和.NET Core 3.1都用于项目的解决方案。我最近不得不将Microsoft.Extensions.DependencyInjection从2.2.0升级到版本3.0.0。但是,现在每当我尝试访问端点时都会遇到运行时错误:

System.InvalidOperationException:没有注册类型为'Microsoft.AspNetCore.Authentication.IAuthenticationHandlerProvider'的服务。 在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider提供程序,类型为serviceType) 在Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService [T](IServiceProvider提供程序) 在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文) 在Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext上下文) 在Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited | 6_0(ExceptionHandlerMiddleware中间件,HttpContext上下文,任务任务) 现在,当我在线搜索时,除了Microsoft文档和GitHub帖子中提到的定义外,我找不到其他东西,在GitHub帖子中它只是说应该提供AuthenticationHandler,并负责为给定方案返回正确的处理程序实例,并且分别。

它显然在AuthenticationMiddleware类的Invoke调用上中断了,但是我相信我读到某个地方,您不应轻易创建自己的authenticationMiddleware,并且该类应“开箱即用”地工作,所以我不太喜欢确定如何解决此问题。

恐怕我对认证的经验不是很丰富,所以我不确定发现问题所需的代码。如果有任何重要遗漏,请发表评论,我将其添加。任何帮助都将不胜感激。

相关问题