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.
Loading...
Related Quiz
- You are creating a website and want to add a folder for storing images, scripts, and CSS files. Which default folder in ASP.NET Core would you typically use?
- You've heard about two-factor authentication for enhancing security. How can ASP.NET Core Identity help in implementing this feature?
- What does the Update-Database command do in the context of ASP.NET Core Identity migrations?
- Your manager wants to prevent users from using their username as their password. Which feature in ASP.NET Core Identity helps with this requirement?
- When performing unit testing in ASP.NET Core, what attribute is commonly used to signify a method as a test method?