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

前端之家收集整理的这篇文章主要介绍了剃刀 – 在身份3中创建声明身份前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Visual Studio 2015脚手架使用UserManager< TUser>不能用于创建ClaimsIdentity.有没有人有一个如何做到这一点的工作示例?

VS2015脚手架抛出错误

  1. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
  2. {
  3. // Note the authenticationType must match the one
  4. // defined in CookieAuthenticationOptions.AuthenticationType
  5. var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
  6.  
  7. // Add custom user claims here
  8. return userIdentity;
  9. }

N.B.:我已经向ApplicationUser添加了与IdentyUser不冲突的属性.

解决方法

UserManager在MVC6版本中已更改.您需要修改代码……
  1. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) {
  2. var authenticationType = "Put authentication type Here";
  3. var userIdentity = new ClaimsIdentity(await manager.GetClaimsAsync(this),authenticationType);
  4.  
  5. // Add custom user claims here
  6. return userIdentity;
  7. }

猜你在找的asp.Net相关文章