简体   繁体   中英

Using Identity 2.1 in ASP.NET for Authentication and Authorization of users

This is my first ASP.NET project, and i have to use MVC 5 and Identity 2.1 for this project.

I have looked for information about the usage of Identity 2.1 for the purpose of Authentication and Authorization but i am still confused because no article explained it with complete details and they needed you to be familiar with older versions and newer articles are all about ASP.NET Core MVC.

Lets suppose i have a fruit table with 3 columns:

id = 1 , name = apple , quantity = 4;

id = 2 , name = orange, quantity = 2;

id = 3 , name = banana, quantity = 3;

. . .

And we have some admin users that they can add other fruits types to the list.

And also admin user can create other user accounts and give them permission to either view or edit one or more fruit records.

Like userid1 can view apple quantity, or userid2 can view and edit orange quantity.

My question is how can i implement this scenario with Identity 2.1? Can i implement it with Roles and Claims? If yes please provide me some sample code.

Thanks, and sorry for my bad English.

You probably can't get all your needs out of the box, but you can extend the basic classes to reach your goal. Here are my thoughts, you can have admin and basic roles, you will need a fruit type master table, and a fruit type - user id privilege table. In your extend authorization class, you need check whether a basic user can access certain fruity type and what kind of privilege he/she has.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM