我在更新.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