The tag in web.config is path-based, whereas MVC works with controller actions and routes.
This is an architectural solution that may not matter much if you just want to ban users who are not logged in, but it matters a lot when you try to apply role-based authorization and when you want to customize user processing. types of unauthorized.
The first case is covered from BobRock's answer.
The user must have at least one of the following roles to access the controller or action
[Authorize(Roles = "Admin, Super User")]
The user must have both of these roles in order to have access to the controller or action.
[Authorize(Roles = "Super User")] [Authorize(Roles = "Admin")]
Users who can access the controller or action are Betty and Johnny
[Authorize(Users = "Betty, Johnny")]
In ASP.NET Core, you can use the principles of claims and policies for authorization through [Authorize] .
options.AddPolicy("ElevatedRights", policy => policy.RequireRole("Administrator", "PowerUser", "BackupAdministrator")); [Authorize(Policy = "ElevatedRights")]
The second is very convenient in large applications where authorization may be required with various restrictions, processing and processing depending on the situation. For this reason, we can expand AuthorizeAttribute and implement various authorization options for our project.
public class CustomAuthorizeAttribute: AuthorizeAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { } }
The " properly completed " authentication method in ASP.NET MVC uses the [Authorize] attribute.
Anastasios Selmanis Jul 26 '18 at 9:43 2018-07-26 09:43
source share