我可以使用 [AllowAnonymous]
属性来允许用户访问 Controller 操作,但是是否有一个属性只允许匿名用户访问某个操作?例如[AllowAnonymousOnly]
最佳答案
没有。它不存在。
但是,您可以通过创建自己的继承自 AuthorizeAttribute 的属性来创建它.
你的看起来像:
public class AllowAnonymousOnlyAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
// make sure the user is not authenticated. If it's not, return true. Otherwise, return false
}
}
关于c# - 如何强制仅匿名访问 Controller 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29513828/