Home > MVC > Role-based Authorization in ASP.NET CORE Example



Role-based Authorization in ASP.NET CORE Example

In this article, we will explain how to use Role-based Authorization in ASP.NET CORE with an example and sample code.


In this article, we will explain how to use Role-based Authorization in ASP.NET CORE with Example. Here we are using Role-based Authorization to controller authorize. We have taken login page and Dashboard page for this activity only admin will access Dashboard page because we are using Role based Authorization on Controller.

 

Required Namespaces

We will need to use the following namespaces.

 

LoginController

we have created login controller and we are assigning Name and Role value into claims.

 

Index.Cshtml

We have created login html page you can see below.

 

DashboardController

We have created Dashboard page only admin role can access page because we are using Role based Authorization on Controller..

 

HomePage.Cshtml

We have created HomePage

 

Startup.cs

We have added yellow highlight code inside Startup.cs .




Note: All contents are copyright of their authors.



Comments



Leave a Reply

Comment:*
Email ID:*


Name:*