You're building a web application that requires different user roles like "Admin," "User," and "Guest." Using ASP.NET Core Identity, how would you restrict access to certain pages only for the "Admin" role?

  • Use [Authorize(Roles = "Admin")] attribute on the controller or action method
  • Use [Authorize(Policy = "AdminPolicy")] attribute with a custom policy
  • Use [Authorize("Admin")] attribute
  • Use [AllowAnonymous] attribute for "Guest"
To restrict access to specific pages for the "Admin" role, you should use the [Authorize(Roles = "Admin")] attribute. This attribute allows only users with the "Admin" role to access the decorated controller or action method.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *