c# - How can I allow anonymous access to an otherwise protected resource through a unique URL in ASP.NET Core
问题描述
To access resources in my API the user needs to be authorized, which is handled by
[Authorize]
I need to find a way to generate a unique URL for a specific resource that can be used to access that resource without the user having to authenticate.
解决方案
您可以将该Authorize
属性应用于该类,这将强制所有端点要求授权。
然后,通过AllowAnonymous
在特定端点上指定属性,您将覆盖上述要求并允许用户在不登录的情况下访问 MyAnonymousEndpoint。
[Authorize]
public class MySecureClass
{
[AllowAnonymous]
public IActionResult MyAnonymousEndpoint()
{
}
}
推荐阅读
- python - 在 Anaconda Spyder 环境中安装 selenium 和 chromedriver 时出现问题
- angular - 如何从 Observable 中获取值
- katalon-studio - Katalon Script:按属性查找元素并单击它
- json - Circe 列表反序列化与最佳尝试和错误报告
- c - 打印从 N 到 1 再从 1 到 N 的所有整数的递归函数
- dafny - 如果我使用不同的 Boogie 后端来检查 Dafny 翻译的 bpl 文件,我能找到非虚假的反例吗?
- javascript - 下拉框主体上的手风琴框阴影
- r - 合并两个数据帧而忽略标题
- wordpress - Wordpress - 如何将动态内容分解为多个 div
- erlang - Ejabberd no etc , sbin 文件夹后 sudo make install