Friday 12 February 2021

Part 27: Login and Register action Link

#5 minutes of reading To implement Login, register and Logged in user name in header update layout page shown below.
In line number 2 from below screen, I have injected SignInManager to access libraries from SignInManager class.
Add logout action method inside Account controller shown below.
Run application and check browser header for action link of Register and Login.
Once you Logged in successful, it shows username shown below with Logout action link.
  I show you in previous article to create user with the help Register view and login with that user to access Mobile Brand controller. But I don’t want any user can modify Brand information and only Admin/Dealer user can access Brand and Product controller and not application user.
Till now I cover Authentication part lets jump into Authorization in Asp.Net core. For any application we have to create default Admin user for application.
For now default Admin user not configured for application. I want an admin user which is default user for application and decide admin related stuff in application. I can either provide database script with initial data of admin user or I can enter data when application run and check the given Admin user available in database if not it will create default user in database. Let's create class which check if Admin user not available in database then it will create admin user. Create a class to insert initial default admin user details from this class to database.
Above class will Seed ‘Administrator’ and ‘Dealer’ and ‘AppUser’ Roles into database for my application and also create default ‘admin’ user with Administrator permissions.
Open Startup.cs file and add RoleManager and UserManager in Configure method of
  Before running application make sure you have deleted user entry from AspNetUser table which I have created using register view.
Run application and check in database table user entry gets created and role created in AspNetRoles table.
Once logged in successfully with above user credential, mobile Brands Index view gets rendered on browser.
In this article I shown you how to seed Roles in AspNetRoles table, in next article I wil show you how to implement Authorization.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home