How can you protect a controller action to be accessible only by users with the role "Admin" using the [Authorize] attribute?

  • [Authorize(Roles = "Admin")]
  • [Authorize("Admin")]
  • [Authorize(Admin)]
  • [Authorize(Role = "Admin")]
To restrict a controller action to users with the "Admin" role, you should use the [Authorize(Roles = "Admin")] attribute. This attribute ensures that only users with the specified role can access the action.
Add your answer
Loading...

Leave a comment

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