加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

剃刀 – 在身份3中创建声明身份

发布时间:2020-12-16 04:34:46 所属栏目:asp.Net 来源:网络整理
导读:Visual Studio 2015脚手架使用UserManager TUser不能用于创建ClaimsIdentity.有没有人有一个如何做到这一点的工作示例? VS2015脚手架抛出错误: public async TaskClaimsIdentity GenerateUserIdentityAsync(UserManagerApplicationUser manager){ // Note
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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读