Easily learn MVC4.0-5 roles

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.