[ASP. net mvc] Using CLK. AspNet. Identity to provide role-based access control (RBAC ),
[ASP. net mvc] Use CLK. AspNet. Identity to provide role-based access control (RBAC) program code download
Download program code: Click here to download
Preface
ASP. NET Identity is an open-source project contributed by Microsoft to provide ASP. NET authentication and authorization mechanisms. In the functional module of ASP. NET Identity, Claims-Based authentication is used to provide the authentication mechanism and Role-Based authorization is implemented to provide the authorization mechanism. Developers apply ASP in the system. NET Identity, you can define which role the user belongs to and which role can use those functions as follows. After the user passes verification, you can use the system functions according to Role authorization.
ASP. NET Identity authorization mechanism allows you to dynamically change the role to which the user belongs during system operation, but cannot dynamically change the functions that the role can use. This is because in ASP. in NET Identity, the user's role settings are stored in the database and can be dynamically changed, while the role can use those function settings is defined in the program code cannot be dynamically changed. Although such an authorization mechanism can meet most development requirements, developers do not have the opportunity to use ASP in development projects that require Dynamic Change of roles to use those functions. NET Identity rich authentication and authorization mechanisms.
Domain Model
Functions that a role can use
public class HomeController : Controller{ [Authorize(Roles = "Admin")] public ActionResult Contact() { ... } [Authorize(Roles = "Guest")] public ActionResult Contact() { ... }}
Role of the user
This article introduces a verification authorization Module Based on ASP. NET Identity development and design: CLK. AspNet. Identity. This Authentication Authorization module provides Role-based access control (RBAC) and disassembles the system authorization into User and Role) permission (Permission ). Developers apply CLK in the system. aspNet. after Identity, you can define which role the user belongs to, which role has the permissions, and which functions can be used by the permissions as follows. After the user passes authentication, you can use the system functions according to the role permissions.
CLK. aspNet. identity authorization mechanism, in addition to continuing to use the inherited from ASP. in addition to the Claims-Based authentication mechanism of NET Identity, you can dynamically change the authorization settings stored in the database during system operation: permissions of the role and role to which the user belongs, this makes the system's authorization settings more flexible and changeable to meet more user needs.
Domain Model
Functions that can be used by Permissions
public class HomeController : Controller{ [RBACAuthorize(Permission = "AboutAccess")] public ActionResult Contact() { ... } [RBACAuthorize(Permission = "ContactAccess")] public ActionResult Contact() { ... }}
Role of the permission
Role of the user
Install and change role permissions Change User Role new system permission program code download
Download program code: Click here to download