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.

Writing a resource-based handler

Writing a resource-based handler - ASP.NET Core Tutorial

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

Start my 1-month free trial

Writing a resource-based handler

- [Instructor] On the last chapter we learned how to write a requirements handler, and on this part, we are going to learn how to write a resource-based handler. To create a resource-based handler, we need to first create a custom class, then we need to implement the requirement handler, and at the end, we need to configure this handler in the Startup.cs class. So, let us go to our project and see all these steps in action. So, in here go to the Solution Explorer. Right click on the Helpers folder, go to Add, Class. We are going to name this class ReportAuthorizationHandler. And click the Add button to create this class. For this class to be a handler, we need to inherit from the base class AuthorizationHandler. So for that, we write in here AuthorizationHandler, and we need to pass two parameters. We need to pass the requirement class. So let us name the requirements SameAuthorRequirement, and the second property that we need to pass is the resource type. So, I'll just write in here…

Contents