LoginSignup
1
2

More than 5 years have passed since last update.

IdentityUser機能にユーザ情報を新たに追加する

Last updated at Posted at 2015-08-07

「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#ってわかりずらいね。誰からも使われないようにするための戦略なんだろう。

ビバ!ユーザーアイデンティティ!!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2