我使用"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而不是模式?
感谢支持
发布于 2016-07-26 06:20:57
将RoleClaimType添加到Startup.cs中的AspNetIdentityManagerService中:
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
https://stackoverflow.com/questions/36744667
复制相似问题