如何确定 ASP.NET 应用程序域生命周期
我们有一个收集计数器统计信息的应用程序,我们希望在执行 iisreset 命令后重置这些值,仅此而已。
微软表示 Application_Start
是:
当第一个资源(例如 作为 ASP.NET 应用程序中的页面) 被要求。应用程序_启动 方法在期间仅被调用一次 应用程序的生命周期。你 可以使用该方法进行启动 任务,例如将数据加载到 缓存并初始化静态值。
这就是我们目前正在做的事情:
protected void Application_Start(object sender, EventArgs e)
{
_counters.Get<AutoCounter>("TAS:RequestCount").Reset();
_counters.Get<AutoCounter>("TAS:RequestTime").Reset();
_counters.Get<AutoCounter>("TAS:TimeBetweenErrors").Reset();
_counters.Get<AutoCounter>("TAS:ErrorCount").Reset();
}
但是,这些会以意想不到的时间间隔重置。什么决定了应用程序域的生命周期何时结束以及在下一个请求时调用此方法?
We have an application gathering counter statistics and we would like the values to reset after executing the iisreset
command and that's all.
Microsoft says Application_Start
is:
Called when the first resource (such
as a page) in an ASP.NET application
is requested. The Application_Start
method is called only one time during
the life cycle of an application. You
can use this method to perform startup
tasks such as loading data into the
cache and initializing static values.
This is how we're currently doing it:
protected void Application_Start(object sender, EventArgs e)
{
_counters.Get<AutoCounter>("TAS:RequestCount").Reset();
_counters.Get<AutoCounter>("TAS:RequestTime").Reset();
_counters.Get<AutoCounter>("TAS:TimeBetweenErrors").Reset();
_counters.Get<AutoCounter>("TAS:ErrorCount").Reset();
}
However, these are resetting at unexpected intervals. What determines when the application domain's life-cycle ends and this method is called on the next request?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Web 应用程序重新启动的原因有很多。此文章包含以下部分列表。
编辑 web.config
编辑 machine.config
编辑 global.asax
bin 中的文件已更改
Web 应用程序的目录,或其中之一
bin 的子目录
创建、重命名目录或
在网络应用程序目录中删除
编辑(因此重新编译)
超过20次,默认设置
机器配置作为一个元素
名为 numRecompilesBeforeApprestart
的
通过各种设置
中的属性
machine.config 中的元素,其中
影响
的重启/关闭
工作进程本身。在 Windows 上
2003 年,未使用 IIS5 隔离时
模式(默认情况下不使用),
这些元素是
忽略,而是
中的设置
IIS 管理器中的应用程序池是
使用
是您的方法很好,但现在您真正想知道的是导致重新启动的原因以及您是否应该感到震惊。
There are a lot of reasons why a Web app gets restarted. This article includes the following partial list.
the web.config is edited
the machine.config is edited
the global.asax is edited
files are changed in the bin
directory of the web app, or one of
the bin's subdirectories
a directory is created, renamed, or
deleted within a web app directory
an ASP.NET file (aspx, asmx, etc.) is
edited (and therefore recompiled)
more than 20 times, a default set in
the machine config as an element
named numRecompilesBeforeApprestart
by way of settings of various
attributes in the
element in the machine.config, which
affect the restart/shutdown of the
worker process itself. On Windows
2003, when not using IIS5 isolation
mode (which is not used by default),
these elements are
ignored and instead the settings in
Application Pools in IIS manager are
used
My guess is that your approach is good but now what you really want to know is what's causing the restart and if you should be alarmed.
在 IIS 6.0 中,应用程序池性能选项卡允许您在指定的空闲时间后关闭 IIS 工作进程。默认情况下启用此功能并设置为二十分钟。
这可能是触发意外的 application_start 事件的原因。
In IIS 6.0, the application pool performance tab allows you to shutdown the IIS worker process after a specified idle time. This is enabled by default and is set to twenty minutes.
This could be the cause of unexpected application_start events being triggered.