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

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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....