首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IdentityManager.AspNetIdentity和MVC5.0应用程序使用不同的角色声明类型

IdentityManager.AspNetIdentity和MVC5.0应用程序使用不同的角色声明类型
EN

Stack Overflow用户
提问于 2016-04-20 13:01:59
回答 1查看 279关注 0票数 0

我使用"IdentityManager.AspNetIdentity“来实现ASP.Net MVC 5.0应用程序的角色和声明。

( IdentityManager.AspNetIdentity)

我注意到,如果在IdentityManager中创建一个新角色并将其分配给特定的用户,则IdentityManager将创建该角色,并使用ClaimType创建一个与“角色”相等的新声明。

图片:索赔情况

现在..。如果我错了,请纠正我:

从MVC应用程序端,我知道默认情况下,框架测试**ClaimType =“

http: //schemas.microsoft.com/ws/2008/06/identity/claims/role

"**,以便在检查安全时实现安全。

图片:解决办法

现在,为了使IdentityManager和MVC应用程序使用相同的角色,我的解决方案是使用与Microsoft相同的ClaimType添加声明。

但是,每当我给用户分配角色时,我如何让IdentityManager用Microsoft而不是“角色”填充ClaimType呢?

或者,在测试用户角色时,我如何使Microsoft.Idghty2.0测试“角色”ClaimType而不是模式?

感谢支持

EN

回答 1

Stack Overflow用户

发布于 2016-07-26 06:20:57

将RoleClaimType添加到Startup.cs中的AspNetIdentityManagerService中:

代码语言:javascript
复制
public class ApplicationIdentityManagerService : 
    AspNetIdentityManagerService<ApplicationUser, string, IdentityRole, string>
{
    public ApplicationIdentityManagerService(ApplicationUserManager userMgr, ApplicationRoleManager roleMgr)
        : base(userMgr, roleMgr)
    {
        RoleClaimType = System.Security.Claims.ClaimTypes.Role;//or streight RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
    }

}

现在,IdentityManager使用Microsoft ("http://schemas.microsoft.com/ws/2008/06/identity/claims/role")。

注ClaimTypes.Role来自System.Security.Claims,而非IdentityManager.Constants

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36744667

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档