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.
Loading...
Related Quiz
- How does the ASP.NET Core Identity system handle migrations in a distributed deployment scenario where multiple instances might attempt to apply migrations simultaneously?
- How can you handle optimistic concurrency in Entity Framework Core?
- Your team is concerned about the security of your new web application. What are some built-in features in ASP.NET Core to help safeguard your application?
- When using Entity Framework Core, how can developers specify relationships like one-to-one, one-to-many, or many-to-many between entities?
- In your ASP.NET Core application, you wish to change some default settings like the application's timezone and culture. Which file should you inspect and modify?