我正在研究ASP.NET应用程序并缓存一些参考数据。在global.asax中的application_start事件中调用创建缓存的代码。我的问题是多次调用application_start事件会减慢应用程序访问速度。为了测试该问题,我重新安装了该应用程序。 application_start事件是在第一次访问应用程序时触发的(正如预期的那样),并且在大约一个小时后再次触发,即使我没有进行任何更改。我没有在应用程序的bin文件中进行任何文件系统更改,并且应用程序池设置为默认的回收设置(1740分钟),所以我不确定为什么要调用该事件。
由于
答案 0 :(得分:4)
我会检查空闲超时设置(默认为20分钟)。如果站点未处理任何20分钟的请求,则工作进程将关闭,因此下次运行该应用程序时,您将获得另一个App Start事件。
答案 1 :(得分:1)
您可以在Global.asax.cs的Application_End方法中记录重启原因,我正在使用此代码:
protected void Application_End(object sender, EventArgs e)
{
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);
}
}