Visual Studio 2015脚手架使用的UserManager<TUser>不能用于创建ClaimsIdentity。有没有人有一个有效的例子来做到这一点?

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 .: 我已为ApplicationUser添加了与IdentyUser不冲突的属性。

最佳答案

UserManager在MVC6版本中已更改。您将需要修改您的代码...

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

关于razor - 在身份3中创建声明身份,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36528624/

10-13 08:04