Confusing logic of [Authorize(Policy = xxx)] #49118
-
Suppose I have 2 auth policies(P1 & P2) in the project, I also have a controller which has many actions and only one uses 'P2'. The codes are like the following, [Authorize(Policy = "P1")]
public class MyController
{
// special action
[HttpGet]
[Authorize(Policy = "P2")]
public IActionResult MyApi() { ... }
// other actions
// ...
} I thought the attribute on method will overwrite the other one on controller. But I'm wrong. It seems that the authz of However, if I use Is it by design? I think it shall be documented. If someone can explain, I'll appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
To my knowledge, these The Simple authorization in ASP.NET Core
Edit: dotnet/AspNetCore.Docs issue for reference |
Beta Was this translation helpful? Give feedback.
-
Hello @LeaFrock and @david-acker ... Note that the docs 🐈🐈🐈 don't track doc requests here. This item will be addressed per your, @david-acker, issue, but note that the best way to open issues for the docs team is to use the This page feedback button and form at the bottom of the English-US topic. Use of the This page feedback form adds metadata to the GitHub issue that cross-links the topic and automatically pings the author. |
Beta Was this translation helpful? Give feedback.
To my knowledge, these
[Authorize]
attributes are indeed designed to work additively when used this way. Although after a quick search, I wasn't able to find this explicitly mentioned in the docs. I'll enter a ticket in dotnet/AspNetCore.Docs to get some documentation added for this.The
[AllowAnonymous]
attribute should then bypass any[Authorize]
attributes:Simple authorization in ASP.NET Core