ASP.NET Identity “Role-based” Claims

后端 未结 3 1689
小蘑菇
小蘑菇 2020-12-30 00:17

I understand that I can use claims to make statements about a user:

var claims = new List();
claims.Add(new Claim(ClaimTypes.Name, \"Peter\"));
         


        
3条回答
  •  猫巷女王i
    2020-12-30 00:48

    This is already done for you by the framework. When user is logged in, all user roles are added as claims with claims type being ClaimTypes.Role and values are role name.

    And when you execute IPrincipal.IsInRole("SuperAdmin") the framework actually checks if the claim with type ClaimTypes.Role and value SuperAdmin is present on the user.

    So don't need to do anything special. Just add a user to a role.

提交回复
热议问题