From the course: ASP.NET Core Identity: Authorization Management

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Custom authorization attributes

Custom authorization attributes - ASP.NET Core Tutorial

From the course: ASP.NET Core Identity: Authorization Management

Start my 1-month free trial

Custom authorization attributes

- [Instructor] We have learned from the last chapter about policy-based authorization in .Net Core, but by implementing policy-based authorization, the policies need to be registered in the Startup.cs class. But there might be a lot of cases where registering all policies using this way is not possible. So in those cases, we can use a custom authorization policy provider. So let us go to our solution and then here, we see that when we want to use a policy, we need to first configure the policy in our Startup.cs file in the ConfigureServices method and then go to the Controller and define it here. Imagine we want to create other policies as well. So in this case, we have just created one for over 15 only. Let us say we want to create another one for over 20 only. We have to go to the Startup.cs file, we need to edit in here. We need to change this value to 20. We need to change the name here because the name needs to be unique. Then we need to go to the Controller. Then make that the…

Contents