Avatar ·

Creating Custom AuthorizeAttribute in ASP.NET Core: Step-by-Step Guide

Hi everyone! I'm new to ASP.NET Core and trying to implement custom authorization attributes for my web application. In old ASP.NET MVC I could simply inherit from `AuthorizeAttribute` and override the `AuthorizeCore` method. But in ASP.NET Core it's different. I need to check if a user has a specific permission in the database before granting access to a controller or action. For example, I have a store, and only users with the "CanEditProducts" permission can edit products. Here's what I tried: ```csharp public class CustomAuthorizeAttribute : AuthorizeAttribute { private readonly string _permission; public CustomAuthorizeAttribute(string permission) { _permission = permission; } protected override boo