如何确定ASP.NET应用程序域的生命周期

我们有一个应用程序收集计数器统计信息,我们希望在执行iisreset命令后重置值,这就是全部.

微软称Application_Start是:

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.

这就是我们目前的做法:

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

但是,它们会以意外的间隔重置.什么决定应用程序域的生命周期何时结束,并在下一个请求中调用方法

解决方法

Web应用程序重新启动的原因有很多.此 article包括以下部分列表.

>编辑web.config
> machine.config已编辑
>编辑global.asax
>文件在bin中更改
Web应用程序的目录,或者其中之一
bin的子目录
>创建,重命名或创建目录
在Web应用程序目录中删除
>一个ASP.NET文件(aspx,asmx等)
编辑(因此重新编译)
超过20次,认设置为
机器配置为元素
命名为numRecompilesBeforeApprestart
>通过各种设置的方式
中的属性
machine.config中的元素,哪个
影响重启/关机
工人过程本身.在Windows上
2003年的时候,没有使用IIS5隔离
模式(认情况下不使用),
这些元素是
忽略而不是设置
IIS管理器中的应用程序池是
用过的

我的猜测是你的方法很好,但现在你真正想知道的是导致重启的原因以及你是否应该警惕.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....