最近我發(fā)現(xiàn)Stackoverflow上有一個非常好的問題.提問者問:為什么在調(diào)用AuthenticationManager.SignIn后,claim仍然可以被添加到Identity并持久化到cookie里.
示例代碼如下所示:
ClaimsIdentity identity = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie );var claim1 = new Claim(ClaimTypes.Country, "Arctica"); identity.AddClaim(claim1); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, identity );var claim2 = new Claim(ClaimTypes.Country, "Antartica"); identity.AddClaim(claim2);
是的,為什么claim2在cookie已經(jīng)設(shè)置完成后還可用.