0

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?

Greggo
  • 181
  • 1
  • 6
  • The app could restart for several reasons (web.config changes, bin directory changes, unhandled exceptions in spawned threads, etc). I would check the answers to this question to see if anything jumps out at you: http://stackoverflow.com/questions/302110/what-causes-an-application-pool-in-iis-to-recycle – rsbarro Jun 06 '11 at 22:23

1 Answers1

1

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);
  }
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
  • Thanks for the code! Ok, it's definitely a change in the bin dir that's causing it. Are there any log events that will tell you what changed? – Greggo Jun 07 '11 at 14:27
  • as far as I know no, you can try with Sysinternals Process Monitor or FileMon, set filter to bin directory and monitor changes in filesystem, and you will see what file is changed. http://technet.microsoft.com/en-us/sysinternals/bb896645 – Antonio Bakula Jun 07 '11 at 14:33
  • Update: discovered that Visual Studio had defaulted to putting a logfile in the bin directory, which of course was being updated every time the database was hit. I've been trying to set permissions to some other folder for the log file, but no success. Do you know any tutorials on permissions? My app is running in the DefaultAppPool – Greggo Jun 07 '11 at 14:59
  • hm, I am not sure what log file we are talking about, maybe would be best to post new question on SO, and more people will see it – Antonio Bakula Jun 07 '11 at 15:05