Greggo
Greggo

Reputation: 181

MVC3 App Restarting Every Pageload

I'm making a MVC 3 app running on IIS 7.5 that uses EntityFramework to access a large database. The framework my company requires for accessing the database initializes connections and sets some thread context and security checks - a process that takes about 30 seconds. This should only run once when the app starts, but it does this every page load.

The way I have it set up now is to have a static method in global.asax to check the HttpContext.Current.Application dictionary to see if a key for the Context class has been set, return the Context if so, otherwise initialize the Context then return it. Every pageload, the dictionary is empty so the Context has to be reinitialized (as checked in Visual Studio 2010).

Before I had it call an initialization method in the Application_Start method in global.asax, and that got hit every pageload too.

Pages still take forever to load even if Visual Studio is not running.

What could possibly be causing the app to reset every pageload?

Upvotes: 0

Views: 396

Answers (1)

Antonio Bakula
Antonio Bakula

Reputation: 20693

You can get a reason for restart in Application_End with this code :

  HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);

  string shutDownMessage = "";

  if (runtime != null)
  {
    shutDownMessage = Environment.NewLine + "Shutdown: " +
                      (string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) + 
                      Environment.NewLine + "Stack: " + Environment.NewLine +
                      (string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
  }

Upvotes: 1

Related Questions