本文介绍了如何强制控制器操作只匿名访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用 [使用AllowAnonymous] 属性,以允许用户访问一个控制器动作,但有只允许匿名用户的操作属性?例如 [AllowAnonymousOnly]
I can use the [AllowAnonymous] attribute to permit a user to access a controller action, but is there an attribute to permit only anonymous users to an action? e.g. [AllowAnonymousOnly]
推荐答案没有。它不存在
不过,您可以通过创建自己的属性从的 AuthorizeAttribute 。
However, you can create it by creating your own attribute inheriting from the 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 } }更多推荐
如何强制控制器操作只匿名访问?
发布评论