在 ASP.NET MVC 中覆盖授权属性 [英] Override Authorize Attribute in ASP.NET MVC
本文介绍了在 ASP.NET MVC 中覆盖授权属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 MVC 控制器基类,我在其上应用了 Authorize 属性,因为我希望几乎所有控制器(及其操作)都得到授权.
I have an MVC controller base class on which I applied the Authorize attribute since I want almost all of the controllers (and their actions along) to be authorized.
但是我需要一个控制器和另一个控制器的未经授权的操作.我希望能够用 [Authorize(false)]
或其他东西来装饰它们,但这是不可用的.
However I need to have a controller and an action of another controller unauthorized. I wanted to be able to decorate them with the [Authorize(false)]
or something but this is not available.
有什么想法吗?
推荐答案
似乎 ASP.NET MVC 4 通过添加 AllowAnonymous 属性.
It seems ASP.NET MVC 4 'fixed' this by adding an AllowAnonymous attribute.
[Authorize]
public class AccountController : Controller
{
[AllowAnonymous]
public ActionResult Login()
{
// ...
}
// ...
}
这篇关于在 ASP.NET MVC 中覆盖授权属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文