6

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?

Jason Berkan
  • 8,734
  • 7
  • 29
  • 39
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • outside of the controller, higher up in the stack just before the controller is called. – Blankman Jun 02 '10 at 20:57
  • If you are trying to figure out which controller is going to be instantiated at run-time, a controllerfactory would help. Hard to say what you mean without an example of what you are trying to accomplish. – Jab Jun 03 '10 at 14:11

4 Answers4

9

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
7

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.

womp
  • 115,835
  • 26
  • 236
  • 269
2

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

jhappoldt
  • 2,406
  • 1
  • 21
  • 24
1

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?

Community
  • 1
  • 1
Soe Moe
  • 3,428
  • 1
  • 23
  • 32