在ASP.Net Core1.0 RTM,我想用這種方法來創建身份:什麼是Asp.Net Core 1.0 RTM中CreateIdentityAsync方法的替代?
userManager.CreateIdentityAsync()
,但我得到這個錯誤:
'UserManager' doesnot contain a definition for 'CreateIdentityAsync'.
到底哪裏出問題了?
在ASP.Net Core1.0 RTM,我想用這種方法來創建身份:什麼是Asp.Net Core 1.0 RTM中CreateIdentityAsync方法的替代?
userManager.CreateIdentityAsync()
,但我得到這個錯誤:
'UserManager' doesnot contain a definition for 'CreateIdentityAsync'.
到底哪裏出問題了?
您可以嘗試IUserClaimsPrincipalFactory
ClaimsPrincipal claimsPrincipal = await _claimsPrincipalFactory.CreateAsync(user);
((ClaimsIdentity) claimsPrincipal.Identity).AddClaim(new Claim("user_id", user.Id.ToString()));
我用ClaimsIdentityFactory()
。這是我的代碼:
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(UserManager<ApplicationUser> manager,
string AuthenticationType)
{
var factory = new ClaimsIdentityFactory<ApplicationUser>();
return await factory.CreateAsync(manager, this, AuthenticationType);
}
Core中沒有ClaimsIdentityFactory。只有一個UserClaimsPrincipalFactory。同樣,沒有ClaimsIdentityAsync,只有CreateUserPrincipalAsync。 – dapug