net core 3.1使用identityServer登录时signin-oidc报Correlation failed的解决方法

  • net core 3.1使用identityServer登录时signin-oidc报Correlation failed的解决方法已关闭评论
  • 147 次浏览
  • A+
所属分类:.NET技术
摘要

Unknown locationMicrosoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()


此问题全网找了很久,也困扰了我很久,始终没有找到解决方法。今天结合网上其他问题的帖子,自己研究的半天,终于找到了这个解决方法,经亲自测试可行。欢迎大牛指导指正。

有时客户收藏的系统地址是认证端的,然后登录之后会转向https://***:101/signin-oidc  报以下错误

An unhandled exception occurred while processing the request.

Exception: Correlation failed.

Unknown location

Exception: An error was encountered while handling the remote login.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

net core 3.1使用identityServer登录时signin-oidc报Correlation failed的解决方法

解决的原理就是,当远程认证错误时,转向最开始的系统首页。

解决方法

 1 services.AddAuthentication(options =>  2                 {  3                     options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;  4                     options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;  5                 })  6                     .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)  7                     .AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>  8                     {  9                         options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; 10                ………………省略内容……………… 11               //------------------此处开始为处理此问题------------------- 12               options.Events=new OpenIdConnectEvents() 13                         { //修复登录成功之后转向signin-oidc并报错的问题 14                             OnRemoteFailure = ctx => 15                             { 16                                 ctx.Response.Redirect($"{ctx.Request.Scheme}://{ctx.Request.Host}"); 17                                 ctx.Response.Body.WriteAsync(null); 18                                 return Task.CompletedTask; 19                             } 20                         }; 21               //---------------------处理此问题结束-------------------------------------- 22 });