Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 404打开/登录oidc多个客户端实例(数据保护问题) 问题_.net_Asp.net Mvc_Cookies_Identityserver4_Openid Connect - Fatal编程技术网

.net 404打开/登录oidc多个客户端实例(数据保护问题) 问题

.net 404打开/登录oidc多个客户端实例(数据保护问题) 问题,.net,asp.net-mvc,cookies,identityserver4,openid-connect,.net,Asp.net Mvc,Cookies,Identityserver4,Openid Connect,我正在开发一个.NETFramework4.7.2MVC应用程序,它总是在负载平衡器后面运行,除非我添加第二个MVC应用程序实例,否则效果很好 IdentityServer4本身正在使用数据保护,但非核心客户端存在此问题 我找不到与.NET framework等效的数据保护。是有,还是我看到了不同的东西 如果我从loadbalancer中删除一个实例,它将再次工作 最小工作示例 app.UseCookieAuthenticationnew CookieAuthenticationOptions

我正在开发一个.NETFramework4.7.2MVC应用程序,它总是在负载平衡器后面运行,除非我添加第二个MVC应用程序实例,否则效果很好

IdentityServer4本身正在使用数据保护,但非核心客户端存在此问题

我找不到与.NET framework等效的数据保护。是有,还是我看到了不同的东西

如果我从loadbalancer中删除一个实例,它将再次工作

最小工作示例 app.UseCookieAuthenticationnew CookieAuthenticationOptions { AuthenticationType=CookieAuthenticationDefaults.AuthenticationType, slidengexpiration=true }; app.UseOpenIdConnectAuthenticationnew OpenIdConnectAuthenticationOptions { ClientId=ClientId, Authority=identityServerUrl, //动态地获取它,在IDS中注册所有可能的值。 //https://github.com/IdentityServer/IdentityServer3/issues/1458 RedirectUri=redirectUrl, PostLogoutRedirectUri=postLogoutRedirectUrl, ResponseType=代码id\u令牌, 范围=范围, SaveTokens=true, TokenValidationParameters=新的TokenValidationParameters { NameClaimType=名称, RoleClaimType=角色 }, RequireHttpsMetadata=false, SignInAsAuthenticationType=CookieAuthenticationDefaults.AuthenticationType, UseTokenLifetime=false, AuthenticationType=OIDC, 通知=新的OpenIdConnectAuthenticationNotifications { SecurityTokenValidated=异步tokenValidatedNotification=> { 尝试 { logger.LogTraceEntering AuthorizationCodeReceived{AuthticketId实体}{response}, tokenValidatedNotification.AuthenticationTicket.Identity、tokenValidatedNotification.Response.StatusCode; var claimstokep=tokenValidatedNotification.AuthenticationTicket.Identity.Claims.ToList; claimsToKeep.addnewclaimid_令牌,tokenValidatedNotification.ProtocolMessage.IdToken; //使用代码获取访问和刷新令牌 pragma warning disable CS0618//类型或成员已过时 var tokenClient=new tokenClient${identityServerUrl}/connect/token,clientId,clientSecret; pragma warning restore CS0618//类型或成员已过时 TokenResponse TokenResponse=等待tokenClient.RequestAuthorizationCodeAsync tokenValidatedNotification.ProtocolMessage.Code,重定向URL; 如果tokenResponse.IsError { 抛出新异常$Error授权用户{tokenResponse.Error},{tokenResponse.ErrorDescription},tokenResponse.Exception; } //使用访问令牌从userinfo检索声明 pragma warning disable CS0618//类型或成员已过时 var userInfoClient=newuserinfoclient${identityServerUrl}/connect/userinfo; pragma warning restore CS0618//类型或成员已过时 UserInfoResponse UserInfoResponse=等待userInfoClient.GetAsynctokenResponse.AccessToken .配置为false; 如果userInfoResponse.IsError { 抛出新的ExceptionuserInfoResponse.Error,userInfoResponse.Exception; } claimstokep.AddRangeuserInfoResponse.Claims; //创建新身份 var claimsIdentity=new ClaimsIdentitytokenValidatedNotification.AuthenticationTicket 身份 .身份验证类型、名称、角色; claimsIdentity.AddClaimsuserInfoResponse.Claims; claimsIdentity.addclaimsclaimstokep; var user=claimsIdentity.Claims.FirstOrDefaultx=>x.Type==sub; 如果user!=null&&user.Value.Contains'@' { var username=user.Value.Split'@'[0]; if!string.IsNullOrEmptyusername { //删除现有的名称声明 var removeClaim=claimsIdentity.Claims.ToList.FirstOrDefaultx=>x.Type ==姓名; 如果是removeClaim!=无效的 { claimsIdentity.RemoveClaimremoveClaim; } //添加用户名作为名称声明 claimsIdentity.AddClaimnew Claimname,username.ToLower; } } tokenValidatedNotification.AuthenticationTicket=新的AuthenticationTicket 索赔性, tokenValidatedNotification.AuthenticationTicket.Properties; 等待任务。FromResult0; } 捕获异常 { logger.LogErrorex、SecurityTokenValidated错误{AuthticketId实体}、{responseStatus}失败、tokenValidatedNotification.AuthenticationTicket.Identity、tokenValidatedNotification.Response.StatusCode; 投 } }, RedirectToIdentityProvider=异步RedirectToIdNotification=> { 尝试 { 如果!BrowserSupportService.isBrowserSupported { RedirectToIdNotification.Response.Redirect/browserNotSupported; 重定向至dpnotification.HandleResponse; } 其他的 { //如果注销,请添加id\u令牌\u提示 如果重定向到DPNotification.ProtocolMessage.RequestType== OpenIdConnectRequestType.Logout { 索赔提示= 重定向至dpnotification.OwinContext.Authentication.User.FindFirstid_令牌; 如果idTokenHint!=null { RedirectToidNotification.ProtocolMessage.IdTokenHint=IdTokenHint.Value; } RedirectToIdNotification.ProtocolMessage.PostLogoutRedirectUri= postLogoutRedirectUrl; 重定向到dpnotification.Options.PostLogoutRedirectUri=postLogoutRedirectUrl; } 如果重定向到DPNotification.ProtocolMessage.RequestType== OpenIdConnectRequestType.Authentication &&IsAjaxRequestredirectToIdpNotification.Request&& RedirectToIdNotification.Response.StatusCode==int-HttpStatusCode.Unauthorized { 重定向到dpnotification.Response.StatusCode=int-HttpStatusCode.Unauthorized; 重定向至dpnotification.HandleResponse; } } 等待任务。FromResult0; } 捕获异常 { logger.LogErrorex,重定向到Identity Provider错误; 投 } } } }; 日志文件的相关部分
几年前我在我工作的公司解决了这个问题。原因是默认ASP.Net身份验证cookie解密仅在创建/加密cookie的服务器上起作用

为了解决这个问题,我非常确定您只需要向web.config文件添加一个机器密钥,并确保两台服务器上的密钥相同

作为第一步,可以尝试复制本文中的值,然后在以后生成自己的密钥(如果可行):

IdentityServer logs are successful, no errors/warnings during this.