我正在调试一个ASP.NET应用程序,它似乎随机丢失了一些静态字段的内容.我做了一些简单的自定义日志记录(因为即使log4net也不稳定),并发现该应用程序正被加载到两个应用程序域中.这是日志中的一个片段:
6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 1 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 2 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 3 6/27/2011 9:01:01 PM /LM/W3SVC/1/ROOT/MyApp-1-129537072581658334: log message 4 6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 5 <- 6/27/2011 9:01:02 PM /LM/W3SVC/1/ROOT/MyApp-4-129537072620628334: log message 6 6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 7 6/27/2011 9:04:50 PM /LM/W3SVC/1/ROOT/MyApp-1-129537074647228334: log message 8
时间/日期之后的项目是当前的应用程序域名.
该应用程序只是一个常规的ASP.NET(而不是MVC)应用程序,它处理一些AJAX请求并将它们传递给一堆ASP.NET库.唯一不寻常的是,其中一个库使用一些反射来查找某些类,然后实例化并在不同的线程上运行它们.但它没有明确地与app域做任何事情.
顺便说一句,日志文件中突出显示的行来自ASP.NET应用程序本身(即不是来自其中一个单独的线程)来自ASPX处理程序.
我正确地解释了日志吗?如果是这样,什么可以导致从多个应用程序域加载和提供应用程序?
编辑:这个问题基本上与这个问题有关:ASP.NET Application state vs a Static object.但是,根据我今天看到的情况,似乎不可能依赖静态字段.我可以将所有内容移动到Application对象,但我想同步会有点麻烦.我越来越相信应用程序做了非标准的事情.
编辑2:我做了一些调查,似乎应用程序和应用程序域之间始终存在1-1关系(这是我期望的).所以我认为我所看到的就是回收利用.
编辑3:经过一些实验和探索之后,我启用了IIS运行状况监控(基于http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx),并发现应用程序快速连续启动两次.这实际上非常令人费解.以下是日志事件:
Event code: 1003 Event message: Application compilation is starting. Event time: 6/28/2011 8:34:31 AM Event time (UTC): 6/28/2011 3:34:31 PM Event ID: d42336b18c264516a4ba5aa1e62df276 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT/MyApp-1-129537488697736549 Trust level: Full Application Virtual Path: /MyApp Application Path: [snip]\MyApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:33 AM Event time (UTC): 6/28/2011 3:34:33 PM Event ID: f7fbecb1ba1a4a24833016cec47458c6 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT-2-129537488729428362 Trust level: Full Application Virtual Path: / Application Path: [snip]\RootApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:40 AM Event time (UTC): 6/28/2011 3:34:40 PM Event ID: 07a3dc31e8804caca1ddc3b2101962e3 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT-3-129537488807712839 Trust level: Full Application Virtual Path: / Application Path: [snip]\RootApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool ---- Event code: 1001 Event message: Application is starting. Event time: 6/28/2011 8:34:40 AM Event time (UTC): 6/28/2011 3:34:40 PM Event ID: db304b519a084fa797fbcfe66fbb0b48 Event sequence: 1 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1/ROOT/MyApp-4-129537488808502885 Trust level: Full Application Virtual Path: /MyApp Application Path: [snip]\MyApp\ Machine name: US-SEA-R9759B2 Process information: Process ID: 7624 Process name: w3wp.exe Account name: IIS APPPOOL\DefaultAppPool
MyApp应用程序位于另一个应用程序(RootApp)中.我期望的是两条日志消息:MyApp启动和RootApp启动.