5

現在、認証されたユーザーからフィールドを公開しようとしていますが、認証されたユーザーに新しいクレームを追加しようとして少し苦労しています。

MVC5 では、次のようなことを行います。

public class ApplicationUser : IdentityUser
{
    public string FullName { get; set; }
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        userIdentity.AddClaim(new Claim("FullName", FullName));
        return userIdentity;
    }
}

ただし、MVC6 でこれを実行しようとすると、オブジェクトとメソッドが見つからないという問題が発生します。CreateIdentityAsync() と DefaultAuthenticationTypes の両方が欠落しているように見えるか、Visual Studio はそう言っています。ID ソースを掘り下げると、CreateIdentityAsync がなくなっていることがわかりますが、DefaultAuthenticationTypes については何も見つからないようです。

現時点では、これは良いことだと思いますが、ここ数日間は気が狂いそうになり、何が問題なのか、どのように変化したのかを理解できればうれしいです。

4

0 に答える 0