I want to set [Authorize] data attribute to the application rather then controllers
[Authorize]
public class CustomerController : Controller {}
With this [Authorize] I can set authorization only for this controller; I want to set it for every controller.
So far I tried these in the program.cs class...
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
services.AddMvc(config =>
{
config.Filters.Add(new AuthorizeFilter(policy));
});
Both didn't work - it builds the app but on browser it doesn't reach to website. So how can I set this attribute globally in .NET 6 ?
builder.services.AddMvc(options => options.Filters.add(new AuthorizeAttribute));
This throws an error
Cannot resolve method 'Add(Microsoft.AspNetCore.Authorization.AuthorizeAttribute)'