Saturday 13 February 2021

Part 28: Authorization and Managing Roles in Asp.Net Core 3.1

#10 minutes of reading
In previous article I shown how to Seed default Roles and User into application. In database default roles and admin user is available now.
Open database and check data inside tables shown below. Source Code available on github

Roles created under AspNetRoles table
Application Users created under AspNetUsers table.
User and Role mapping created under AspNetUserRoles.
All above data insertion performed from Seed class created in previous article. Let’s append authorization in application. Open MobileBrands and ProductDetails controller.
Run application and login with Admin user and check browser it rendered Mobile Brands controller.
Create Dealer user with the help of Register view to create new user.
  Login with Dealer user shown below.
Application denied for dealer user while accessing MobileBrand controller, dealer user created but role not yet assigned to dealer user.
  Go to Account controller and implement below piece of code shown below.
Create view for manageUserRole and AddRole action methods.
Run application, login with Admin user shown below. Highlighted ManageUserRole appeared only for Admin user.
Once you click on ManagerUserRole, it will rendered ManageUserRole view, click on AddRole action link highlighted below.
Once you click on AddRole, it will rendered AddRole view. Tick Dealer checkbox highlighted to assign Dealer role for User(Dealer).
Below screen is from database managing roles for Dealer user.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home