Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there events for before a controller is run?

I know there are events for before/after a action is fired.

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

like image 241
Blankman Avatar asked Jun 02 '10 20:06

Blankman


2 Answers

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.

like image 147
Darin Dimitrov Avatar answered Oct 26 '22 12:10

Darin Dimitrov


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.

like image 32
womp Avatar answered Oct 26 '22 11:10

womp