I have a problem that happens rarely enough but anyway could be caught. The problem is sometimes there is huge time delays when I call some controller’s action. I’ve logged the time and result looks very strange:
> -->BeginRequest: /Data/MyController Now: 17:47:37:248 Thread id = 22
> ---->Prerequest: /Data/MyController Now: 17:47:37:249 Thread id = 22
> ------>Init DataController: /Data/MyController Now: 17:47:37:250 Thread id = 22
> ------>/Data/MyController executing: Now: 17:47:46:302 Thread id = 22
> == /Data/MyController inside: now is 17:47:46:304
BeginRequest and Prerequest are events logged into Global.asax, and Init is from controller.Initialize override method, executing – from OnActionExecuting in controller.
As you can see there is almost 10 seconds between initializing and execution of controller. I don’t understand what is going on during this period time. What events should I check to see?
There are many things that could happen between the Initialize method and entering the controller action. You may take a look at the following article which provides an in-depth overview. And you can download the poster here.
Basically after initializing the controller the steps that take place are:
There’s a slight error in the diagram shown in the article in which step 1 and 2 are inverted. In fact authorization filters execute before model binders.
So what you should be looking for in your code is custom authorization filters, custom model binders and custom action filters. All those could be responsible for the slowdown you are observing between the initialization logic of your controller and entering the controller action.