MVC3应用程序重新启动每一个页面加载 [英] MVC3 App Restarting Every Pageload

查看:215
本文介绍了MVC3应用程序重新启动每一个页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个MVC 3应用程序在IIS 7.5上运行,使用的EntityFramework访问的大型数据库。我公司需要访问数据库的框架初始化连接,并设置一些线程上下文和安全检查 - 这一过程大约需要30秒。应用程序启动时,这应该只运行一次,但它这样做的每一页的负荷。

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.

我现在设立的方式是在Global.asax的一个静态方法来检查HttpContext.Current.Application字典,看是否为Context类的关键已定,返回上下文如果是这样,否则初始化上下文,然后返回。每一个页面加载,字典是空的,所以上下文已重新初始化(如Visual Studio 2010中选中)。

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).

在我有它调用初始化方法在Global.asax中的Application_Start方法中,而腹背受敌的每个页面加载了。

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

页面仍然采取永远即使Visual Studio是没有运行加载。

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

怎么可能会导致应用程序的每一个页面加载重置?

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

推荐答案

您可以得到一个重启理由Application_End这个code:

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);
  }

这篇关于MVC3应用程序重新启动每一个页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆