同时将 AuthorizeAttribute 应用于控制器类和操作

2024-01-20

是否有一种方法可以在具有 Authorize 属性的控制器类的一个操作中忽略 [Authorize] 属性?

        [Authorize]
        public class MyController : Controller
        {
           [Authorize(Users="?")]//I tried to do that and with "*", but unsuccessfuly,
           public ActionResult PublicMethod()
           {
           //some code
           }

           public ActionResult PrivateMethod()
           {
           //some code
           }
        }

只是 PrivateMethod() 应该需要身份验证,但它也是必需的。

PS:我不想制作自定义授权过滤器。

[]'s


您可以使用[允许匿名]

 [Authorize]
 public class MyController : Controller
 {
     [AllowAnonymous]
     public ActionResult PublicMethod()
     {
           //some code
     }

     public ActionResult PrivateMethod()
     {
           //some code
     }
  }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

同时将 AuthorizeAttribute 应用于控制器类和操作 的相关文章

随机推荐