什么是Asp.Net Core 1.0 RTM中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); 
    } 
+0

Core中没有ClaimsIdentityFactory。只有一个UserClaimsPrincipalFactory。同样,没有ClaimsIdentityAsync,只有CreateUserPrincipalAsync。 – dapug