Asp.net is a small example of simple permissions.

Source: Internet
Author: User
Recently, when I was reading an Asp.net book (written by Chinese people), I mentioned a small example of simple permission. I think it is clear and representative,
Therefore, the implementation principle is briefly introduced here.
Its core is to establish the relationship between users, roles, functions, and module functions. The database design is as follows:

1. User Role table

User table
Field: userid auto-incrementing Field

Username
Password

Roletable (role table)
Field
Roleid auto-incrementing Field

Rolename
 
User Role table userrole
Field
Userroleid (auto-incrementing field)
Userid
Roleid

User tables and role tables are associated through the user role table. The relationship between users and roles is many-to-many.

2 Role permission table roleright
Field
rolerightid auto-incrementing field
roleid
modulefunctionid

here, we will parse it. For example, the user Tom has an administrator role (assuming that the role is in the roletable table, if the next record
roleid rolename
2 Admin
appears in the roleright table, there are records in the following form
rolerightid roleid modulefunctionid
1 2 10
2 2 11

That is to say, roleid = 2 administrator role, with moduleidfunctionid = 10 and 11 Permissions

Next, let's look at it.

3. module table)
Field
Moduleid modulename URL
1. Student profile XXXXX
2. Instructor profile xxxxxxx

4 modulefunction table (module-menu)

Field
Modulefunctionid moduleid functionid
.....................
10 1 1
11 1 2

5 function table (menu)
Field
Functionid functioname
1 add
2 update
3 Delete
4 search

You can see that the Administrator has 10 or 11 permissions, which can be found in the modulefunction table, that is, in the moduleid = 1 (student profile) module, there are two types
What is the executable function? You can check functionid. The ADD and update functions are available.

The advantage is that "modules", "functions", "groups", and "people" can be added at will without affecting each other. You can grant permissions directly to each user, assign permissions to a type of user, and grant permissions to the role.
But in fact, it is generally not necessary to set up a function table to grant these permissions, and crud will be used in both the following steps.



 

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.