开发者

ASP.NET MVC 2: Does the method OnPreAction exist in Controller class?

If it does, why can't I override it in my code?

protected override bool OnPreAction(string actionName, System.Reflection.MethodInfo methodInfo)
{
    //do stuff

    return base.OnPreAction(actionName, methodInfo);
}

The posted code is in a Controller wich extends from Controller class. When I co开发者_开发技巧mpile I get this error:

'Namespace.Controllers.XXController.OnPreAction(string, System.Reflection.MethodInfo)': no suitable method found to override

If the method doesn't exist, is there anyone which replace it?

If it does exist, whats the problem in my code?

Please help!

Thanks


You should override OnActionExecuting.


There is no such method. You probably want OnActionExecuting


You're looking for ActionFilter attributes. You can easily roll your own pre/post processing for either a single action or every action in a controller.

BTW, some standard filters based on the same mechanism are included in ASP.NET MVC, such as the Authorize attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜