我在更新.NET .Net 4.6.2/MVC5中的ASP.Net Identity 2.2.1声明时遇到问题。 更新索赔后,它通常会发送一个更新的cookie到浏览器,一切正常,但有时没有设置cookie头被发送到浏览器。ASP.NET身份:在修改声明后没有更新cookie
我已经无法找出任何图案,当它发生时,它失败以外的其他的服务器发送在会议圆满响应
Persistent-Auth: true
HTTP标头值。我不知道是什么导致这个头值被设置,它有时会出现在会话中,一旦它开始发送它,它将被发送到会话的其余部分,并尝试更新声明将永远不会再为该会话工作。
据我所见,我已经硬编码isPersistent参数在每次调用ASP.Net身份时都是false,而且我看不到任何可能与此头相关的其他内容。
我使用用于更新的权利要求的代码是
public static void UpdateClaims(List<Claim> claims)
{
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var newIdentity = new ClaimsIdentity(HttpContext.Current.User.Identity);
foreach (Claim claim in claims)
{
Claim oldClaim = newIdentity.FindFirst(claim.Type);
if (oldClaim != null && oldClaim.Type != "")
{
newIdentity.RemoveClaim(oldClaim);
}
newIdentity.AddClaim(claim);
}
authenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(newIdentity), new AuthenticationProperties { IsPersistent = false });
}
这是正在从MVC动作方法调用。
有没有人有什么建议可能会出错或甚至只是一个起点在哪里看?我不知道是什么导致了这个persistent-auth头,但它看起来与问题有关;无论是问题的原因还是症状,我都不知道。
我使用ASP.Net Identity 2.2.1与.Net 4.6.2。 我在Windows Server 2012R2上运行,并且问题似乎与IE11,Chrome和Firefox一起发生。 我正在使用Fiddler 4.6.3来查看http标题/响应。
更新: 我注意到,它似乎只在启用Windows身份验证时出错。我的服务器有一个设置,允许用户名/密码,Windows身份验证或两者(用户可以选择使用用户名/密码作为不同的用户登录)。当使用Windows身份验证时,我最初使用Windows对用户进行身份验证,然后设置一个cookie,然后将该cookie用于会话中的所有未来请求。 如果禁用了Windows身份验证,则更新这样的声明总是有效。如果启用了Windows身份验证,更新声明通常的作品。
我认为你必须退出并登录才能更新cookie中的声明 – Saravanan