netcore3.1使用identityServer登录时signin-oidc报Correlationfailed的解决方法

博客 分享
0 345
张三
张三 2022-07-20 20:02:03
悬赏:0 积分 收藏

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<TOptions>.HandleRequestAsync()

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

解决方法

 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 });

 

 

posted @ 2022-07-20 19:56 马克部落格 阅读(0) 评论(0) 编辑 收藏 举报
回帖
    张三

    张三 (王者 段位)

    821 积分 (2)粉丝 (41)源码

     

    温馨提示

    亦奇源码

    最新会员