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.
Loading...
Related Quiz
- Your team lead mentions the use of a "_Layout.cshtml" file in your ASP.NET Core project. What is the primary role of this file?
- In a web application you are developing, you want to ensure that certain middleware only runs for specific routes or URLs. How can you achieve this in ASP.NET Core?
- The ________ template in ASP.NET Core ensures that JavaScript dependencies are managed using the Node package manager.
- In the context of Razor, what were "Master Pages" used for in the older versions of ASP.NET?
- In integration testing for an ASP.NET Core application, what is typically mocked to ensure tests don't affect real data?