开发者

Are there events for before a controller is run?

I know ther开发者_JS百科e are events for before/after a action is fired.

Is there anything higher up in the stack like before a controller is called?


There's no such notion as running a controller. Controllers are not run. They are classes which are instantiated and actions (methods) are invoked on them.

You could decorate your controller action with a custom [ActionFilter] attribute in which you could override the OnActionExecuting which will be called before the controller action is invoked. This technique also allows you a better separation of concerns.


ASP.Net MVC still runs through the HttpApplication pipeline, so you can still handle any of the events from BeginRequest through to PreRequestHandlerExecute by adding handlers to Global.asax.


Many application lifecycle events can be handled in the Global.asax file.


Please see the following SO question which explain the lifecycle in ASP.NET MVC.

What is the 'page lifecycle' of an ASP.NET MVC page, compared to ASP.NET WebForms?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜