【发布时间】:2014-09-21 02:38:52
【问题描述】:
我在我的应用程序中设置了一些自定义 ActionFilterAttributes,并使用 OnActionExecuting 进行一些检查。它工作正常,除非我从控制器内运行操作:
public class CarBoardController : GlobalController
{
[HttpPost, ActionProperties(AccessLevel.Granted)]
public ActionResult CarBoard(int carId)
{
var carModel = _businessLogic.GetCarForCarId(carId);
if (carModel == null)
{
// if null create one
carModel = CreateCarForCarId(carId);
}
var model = JsonConvert.SerializeObject(carModel);
return PartialView(new CarViewModel(model));
}
[ActionProperties(AccessLevel.Admin)]
public ICarBoardNode CreateCarForCarId(int carId)
{
return _businessLogic.CreateCarForCarId(carId);
}
}
public class GlobalController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
...
}
}
OnActionExecuting 在 CarBoard 之前被点击一次,然后调用 CreateCarForCarId 但从未点击 OnActionExecuting。
我的 businessLogic 包含检查以确保只有管理员可以创建汽车,但我原以为这会让我甚至不必点击 businessLogic。
有什么想法吗?
谢谢,
【问题讨论】: