In an online quiz application, you want to ensure that only teachers can create or edit questions. Which attribute in ASP.NET Core will help you achieve this functionality?

  • [AllowAnonymous]
  • [Authorize]
  • [Authorize(Roles = "Student")]
  • [Authorize(Roles = "Teacher")]
To restrict the creation or editing of questions to teachers only, you would use the [Authorize(Roles = "Teacher")] attribute. This ensures that only users with the "Teacher" role can access the specified resources. [AllowAnonymous] would allow everyone, [Authorize] is a generic authorization attribute, [Authorize(Roles = "Student")] restricts to students only, which is the opposite of the desired behavior.
Add your answer
Loading...

Leave a comment

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