「Add custom user claims here」の下に値を追記する。
※自動生成されるテーブル「AspUserInfo」?をカスタムしてUserに変更しています。それのEntityパーシャルして追記。
filename
public partial class User : IUser<decimal>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, decimal> manager, string authenticationType)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
// Add custom user claims here
userIdentity.AddClaim(new Claim(ClaimTypes.Email, "xxxxx@xxxx.xxx.xx"));
return userIdentity;
}
}
取り出し方は
filename
var principal = HttpContext.Current.User as ClaimsPrincipal;
var email = principal.Claims.Where(x=> x.Type == ClaimTypes.Email).Value;
C#ってわかりずらいね。誰からも使われないようにするための戦略なんだろう。
ビバ!ユーザーアイデンティティ!!