Original http://www.cnblogs.com/ybst/archive/2012/11/01/2749362.html
A system permission model may be simple or complex. However, if you have mastered the simple foundation, complicated things can be well solved.
We can start from simple things. Open the table webpages_roles and add two roles:
Open views \ ACCOUNT \ index. cshtml and make the following changes:
Add the following JavaScript code:
Make sure that the template file, views \ shared \ _ layout. cshtml, references the relevant JS library file:
Add action to accountcontroller:
The final running result is as follows:
Summary of this article:
1) You can use the methods provided by the system. Web. Security. Roles class to determine and manage roles.
2) You can add attribute: [authorize (roles = "members, managers")] to the Controller class or method (action) to limit the access of a specific role.
3) The complex permission management system can be expanded on this basis.
4) This article contains a simple example of Ajax processing.
A system permission model may be simple or complex. However, if you have mastered the simple foundation, complicated things can be well solved.
We can start from simple things. Open the table webpages_roles and add two roles:
Open views \ ACCOUNT \ index. cshtml and make the following changes:
Add the following JavaScript code:
Make sure that the template file, views \ shared \ _ layout. cshtml, references the relevant JS library file:
Add action to accountcontroller:
The final running result is as follows:
Summary of this article:
1) You can use the methods provided by the system. Web. Security. Roles class to determine and manage roles.
2) You can add attribute: [authorize (roles = "members, managers")] to the Controller class or method (action) to limit the access of a specific role.
3) The complex permission management system can be expanded on this basis.
4) This article contains a simple example of Ajax processing.