Does changing any sub-directory or file in an ASP.NET application recycles the app pool

亡梦爱人 提交于 2019-12-23 03:45:46

问题


I thought I knew ASP.NET well, until a couple of hours ago. I am aware an IIS can recycle an app domain due to a variety of reasons including changes to web.config/bin/App_GlobalResources etc. file/directories, or otherwise on schedule or on specific events (like reaching a specific memory threshhold).

I was very sure my code was NOT hitting any of these conditions. Basically a regular http request would trigger a small task in a background thread (ThreadPool.QueueUserWorkItem) that woould lead to writing of a pdf file inside a sub-directory of my ASP.NET app.

This sub-directory had nothing that would qualify it for causing a app recycle. It was something like:

My Site\CompanyName\Mailer\UploadFiles

Please don't suggest reasons like configuration or bin directory change, the code is changing nothing in ASP.NET folders. Its writing to a pdf file inside a non-ASP.NET directory.

I used the Application_End event to figure out the reason of recycle (using reflection as suggested here: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx) and got this:

_shutDownMessage=Directory rename change notification for 'd:\Projects\MyProject\trunk\dev'.
dev dir change or directory rename
HostingEnvironment initiated shutdown
HostingEnvironment caused shutdown
Directory rename change notification for 'd:\Projects\MyProject\trunk\dev'.
dev dir change or directory rename

I am practically stumped. I am very sure I have written code on other projects which writes under the app's sub-direcories without causing app recycles. But not in this case.

Am I missing something? Is it expected for IIS to recycle the app domain trying to write to any sub-directory of the app from the ASP.NET app itself?


回答1:


There is a thingy called FileChangesMonitor which has a list of folders to watch and will trigger an app recycle if any of these change. It seems that as soon as a resource (an html page, an image, or, in your case, a pdf) is served through an HTTP request, the folder where it is located becomes an ASP.NET folder, i.e. is added to the list and monitored for changes. And it does not matter whether the resources are located inside or outside the application root. I experienced this problem with folder deletes, but I guess the same thing would occur with renames. This is frustrating, because it makes serving volatile static resources very difficult.



来源:https://stackoverflow.com/questions/19941260/does-changing-any-sub-directory-or-file-in-an-asp-net-application-recycles-the-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!