ASP.NET MVC 2 - 如何覆盖单个控制器操作的注释?

时间:2010-07-15 05:10:27

标签: c# asp.net-mvc-2 annotations

我有一个所有控制器继承的BaseController。 CaseController具有[Authorize]注释,因此所有控制器都需要授权。

但我刚刚意识到单个控制器操作不一定需要授权。如何只为那一个控制器动作关闭[授权]?

using System.Web.Mvc;
using Unleashed.Service.Interfaces;

namespace Controllers
{
    [Authorize]
    [RequireHttps]
    public class BaseController : Controller
    {
    }
} 

通过来自其他站点的POST调用控制器操作。他们通过传递令牌进行授权。它们不会通过表单身份验证授权。

[Authorize=false] // doesnt compile
[Authorize(false)] // doesnt compile
public ActionResult DoSomething(string token, string data)
{
}

1 个答案:

答案 0 :(得分:0)

通过创建一个不从BaseController继承的新控制器,并将操作添加到该控制器来解决。现在,这一个操作不需要授权,所有现有操作都保持原样。