【发布时间】:2020-06-15 14:28:04
【问题描述】:
我想创建一个执行以下操作的自定义 AuthorizeAttribute:
- 如果请求的URL包含查询参数id,则需要正常授权
- 如果请求的网址不包含查询参数id,则不需要授权
阅读https://docs.microsoft.com/en-us/aspnet/core/security/authorization/iauthorizationpolicyprovider?view=aspnetcore-3.1 在这种特殊情况下并不能说明问题。
阅读How do you create a custom AuthorizeAttribute in ASP.NET Core? 也不能说明问题,因为它取决于声明。
【问题讨论】:
-
另一种看待它的方式是,经过身份验证的用户被授予“无需在 URL 中传递 ID 即可访问端点”权限,即声明。 sticking to patterns that are familiar to people 有话要说。
标签: c# asp.net-core