我使用以下代碼添加了宣告
var claims = new List<Claim>
{
new Claim(Constants.ClaimTypes.BUSINESS_ID, user.BusinessID.ToString()),
new Claim(Constants.ClaimTypes.NAME, user.FullName),
new Claim(Constants.ClaimTypes.IMAGE, user.ProfileUrl ?? user.LogoUrlEn ?? user.LogoUrlEn ?? ""),
new Claim(Constants.ClaimTypes.EMAIL, user.Email),
new Claim(Constants.ClaimTypes.USER_ID, user.UserID.ToString()),
new Claim(Constants.ClaimTypes.ROLE, user.RoleID.ToString()),
new Claim(Constants.ClaimTypes.RIGHTS, string.Join(',', user.RolesRights.Select(S => $"{S.EntityName}|{S.EntityID}|{S.RightID}")))
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
IsPersistent = true,
RedirectUri = "/Authentication/Login"
};
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
當有人更新個人資料圖片時我需要更新宣告我需要更新它我該怎么做?
我嘗試了幾種解決方案,但沒有任何效果。
當有人比當前更新個人資料圖片時,它必須注銷并再次登錄才能看到效果。
uj5u.com熱心網友回復:
如您所知,登錄時宣告存盤在 cookie 中。
因此,如果要更新宣告,則需要使用更新的宣告重新呼叫登錄用戶代碼。
與之前添加的宣告代碼一樣:
var claims = new List<Claim>
{
new Claim(Constants.ClaimTypes.BUSINESS_ID, user.BusinessID.ToString()),
new Claim(Constants.ClaimTypes.NAME, user.FullName),
new Claim(Constants.ClaimTypes.IMAGE, user.ProfileUrl ?? user.LogoUrlEn ?? user.LogoUrlEn ?? ""),
new Claim(Constants.ClaimTypes.EMAIL, user.Email),
new Claim(Constants.ClaimTypes.USER_ID, user.UserID.ToString()),
new Claim(Constants.ClaimTypes.ROLE, user.RoleID.ToString()),
new Claim(Constants.ClaimTypes.RIGHTS, string.Join(',', user.RolesRights.Select(S => $"{S.EntityName}|{S.EntityID}|{S.RightID}")))
};
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
IsPersistent = true,
RedirectUri = "/Authentication/Login"
};
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/512594.html
