8

Visual Studio 2015スキャフォールディングはUserManager<TUser>を使用しており、ClaimsIdentityの作成には使用できません。誰かがこれを行う方法の実例を持っていますか?ID 3にクレーム識別情報を作成

VS2015の足場は、エラーがスローされます。

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 
    return userIdentity; 
} 

N.B:私はIdentyUserと競合しないApplicationUserにプロパティを追加しました。

+0

足場はどんなエラーを投げますか?あなたが投稿したメソッドは、それが 'ClaimsIdentity'を返していることを示します – Nkosi

+0

UserManager にCreateIdentityAsyncまたはDefaultAuthenticationTypesの定義が含まれていません – Ungaro

+0

再現するにはVS2015 MVC 6テンプレートを使用して新しいASP.NET Webプロジェクトを作成します。 ApplicationUser.csのモデルでは、System.Security.ClaimsおよびMicosoft.AspNet.Identityへの参照を追加し、上のコードをApplicationUserクラスに挿入します。上記のコメントに記載されているエラーを参照してください。 – Ungaro

答えて

10

MVC6バージョンでUserManagerが変更されました。あなたのコードを変更する必要があります...

public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { 
    var authenticationType = "Put authentication type Here"; 
    var userIdentity = new ClaimsIdentity(await manager.GetClaimsAsync(this), authenticationType); 

    // Add custom user claims here 
    return userIdentity; 
} 
+0

ありがとう、Nkosi! – Ungaro

+2

認証タイプ:https://msdn.microsoft.com/en-us/library/system.security.claims.authenticationtypes(v=vs.110).aspx – Ungaro

+0

私はDAL/DTOクラスを新しいプロジェクトに追加する方法を学習していましたパブリックデモプロジェクトAltostratusのASPNETCOREに基づいて、これらの非同期メソッドのうちの2つがあることに気づいた場合、 'UserManager manager'と' UserManager manager、string authenticationType'の両方が必要ですか?私はあなたの中に見ているように、タイプメッセージをハードコードしています。 – Edward

関連する問題