Total Page Preview:   000000000300

Explain Claims based authorization in Asp.Net Core MVC?

Claims based authorization in Asp.Net core MVC 

Claims-based authorization in ASP.NET Core MVC is a method of controlling access to resources and actions based on claims associated with the authenticated user. Claims are key-value pairs that represent information about the user, and they can be used to determine what a user is allowed to do within your application. This type of authorization is more flexible and fine-grained compared to role-based authorization.
Here's an example of how to implement claims-based authorization in ASP.NET Core MVC:
1-Create a new ASP.NET Core MVC project if you don't already have one.
2-In the Startup.cs file, configure authentication and authorization in the ConfigureServices and Configure methods.
1-Define an action method in a controller that requires claims-based authorization. In this example, we'll create an action that can only be accessed by users with a "Admin" claim.
1-When a user logs in, ensure that the claims are assigned to the user. You can do this during the login process or when you create and authenticate the user. For example, in your login controller:
In the code above, we've added a custom "Role" claim to the user with a value of "Admin."
1-Create a view for the "AdminOnlyAction" action.
Now, when a user tries to access the "AdminOnlyAction" action, they will only be allowed if they have the "Role" claim with a value of "Admin."
Claims-based authorization allows you to be more fine-grained in specifying what a user can do based on their claims. You can also use policies and requirements to create more complex authorization logic if needed.


Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn :





Facebook User: