梦见你的名字 发表于 2022-8-30 03:22:10

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

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

有时客户收藏的系统地址是认证端的,然后登录之后会转向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.HandleRequestAsync()
https://img2022.cnblogs.com/blog/1799692/202207/1799692-20220720193723073-612397193.png
解决的原理就是,当远程认证错误时,转向最开始的系统首页。
解决方法
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 }); 
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: net core 3.1使用identityServer登录时signin-oidc报Correlation failed的