ASP.NET application_start 事件被触发

发布于 2024-11-24 12:10:08 字数 298 浏览 2 评论 0原文

我正在开发 ASP.NET 应用程序并缓存一些参考数据。创建缓存的代码在 global.asax 的 application_start 事件中调用。我的问题是 application_start 事件被多次调用,这会减慢应用程序的访问速度。为了测试这个问题,我重新安装了该应用程序。 application_start 事件在第一次访问应用程序时被触发(如预期),并且在大约一个小时内再次触发,即使我没有进行任何更改。我没有在应用程序的 bin 文件中进行任何文件系统更改,并且应用程序池设置为默认回收设置(1740 分钟),因此我不确定为什么要调用该事件。

谢谢

I am working on an ASP.NET application and caching some reference data. The code to create the cache is invoked in the application_start event in global.asax. My problem is that the application_start event is being invoked multiple times which slows the application access. To test the issue I reinstalled the application. The application_start event was fired on first access to the application (as expected) and again in about an hour even though I did not make any changes. I am not making any file system changes in the application's bin file, and the application pool is set to default recycle settings (1740 minutes), so I am not sure why the event is being invoked.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烈酒灼喉 2024-12-01 12:10:08

我会检查空闲超时设置(默认为 20 分钟)。如果站点在 20 分钟内没有处理任何请求,工作进程将关闭,因此此后下次运行应用程序时,您将收到另一个应用程序启动事件。

I would check the Idle Time-out setting (defaults to 20 minutes). If the site doesn't process any requests for 20 minutes, the worker process will shut down, therefore the next time you run the app thereafter, you will get another App Start event.

独木成林 2024-12-01 12:10:08

您可以在 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);
  }
}

You could log reason for restart in Application_End method of Global.asax.cs, I am using this code :

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);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文