In complex scenarios, instead of using simple roles or claims, you might need a custom authorization policy. How do you apply a custom policy using the [Authorize] attribute?
- [Authorize(Policy = "CustomPolicy")]
- [Authorize("CustomPolicy")]
- [Authorize(CustomPolicy)]
- [Authorize(Roles = "CustomPolicy")]
To apply a custom authorization policy using the [Authorize] attribute, you should use the syntax [Authorize(Policy = "CustomPolicy")]. This tells ASP.NET Core to use the "CustomPolicy" when authorizing access to the action or controller.
Loading...
Related Quiz
- When configuring ASP.NET Core Identity, the _________ class is used to specify policies like password strength and lockout duration.
- A new developer joins your team and is unfamiliar with the structure of ASP.NET Core projects. They ask you where the core application logic, such as controllers and models, resides. What would be your response?
- What is the significance of the MapFallbackTo method in endpoint routing?
- The __________ file in an ASP.NET Core project contains routes, middleware configurations, and other app initializations.
- How can you make certain sections optional in a Razor Layout View?