创建、重命名或删除文件夹时 ASP.NET 重新启动
更新——复制问题的过程:
1) 在c:\projects\restart-demo处创建一个网站项目
2) 添加默认的 web.config 和一个虚拟的 aspx 页面< strong>test.aspx
3) 将 IIS 映射到根文件夹 c:\projects\restart-demo
4) 使用 perfmon、运行状况监控、global.asax 中的跟踪来监控应用程序重新启动Application_End等
5) 浏览器中请求页面 http://localhost/test.aspx
application start< /em>
6) 创建新文件夹 c:\projects\restart-demo\asdf
application end
7) 在浏览器中请求页面 http://localhost/test.aspx
应用程序启动
8) 重命名文件夹c:\projects\restart-demo\asdf 到 c:\projects\restart-demo\asdf1
应用程序端
结束更新
我们正在使用后端 CMS 来生成ASP.NET 站点中的文件和文件夹。
用户可以创建/修改/删除文件并将这些文件推送到网络场。
我们注意到一个问题:
当用户创建、重命名或删除文件夹时,会导致应用程序 要重新启动的域。结果, session、缓存等全部丢失。
请注意,它也不需要是像 /bin 或 /App_Code 这样的特殊文件夹。
有什么办法可以阻止这种行为吗?
它确实会影响性能,原因有两个:
- 应用程序域重新启动时缓存被转储
- 重新启动后应用程序域需要重新构建
UPDATE -- process to replicate issue:
1) Create a website project at c:\projects\restart-demo
2) Add default web.config and a dummy aspx page test.aspx
3) Map IIS to point to the root folder c:\projects\restart-demo
4) Monitor application restarts using perfmon, health monitoring, tracking in global.asax Application_End, etc.
5) Request page in browser http://localhost/test.aspx
application start
6) Create new folder c:\projects\restart-demo\asdf
application end
7) Request page in browser http://localhost/test.aspx
application start
8) Rename folder c:\projects\restart-demo\asdf to c:\projects\restart-demo\asdf1
application end
end update
We are using a back-end CMS to generate files and folders in an ASP.NET site.
Users are able to create/modify/delete files and push these out to the web farm.
One problem we have noticed:
When the user creates, renames or deletes a folder, it causes the App
Domain to restart. As a consequence,
session, cache, etc. are all lost.
Note it doesn't need to be a special folder like /bin or /App_Code either.
Is there any way to prevent this behavior?
It is really hampering performance for two reasons:
- Cache is dumped when app domain restarts
- App domain needs to be re-built after restart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当添加到 Global.asax 中的 Application_Start() 时,此代码似乎可以解决该问题:
http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using- Directory-delete.aspx
通过这些更改,我可以创建/修改/删除文件夹,而不会导致应用程序重新启动。
不清楚这是否是最佳解决方案——不知道调用 StopMonitoring 是否会产生不需要的副作用。
This code appears to resolve the issue, when added to Application_Start() in Global.asax:
http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using-directory-delete.aspx
With these changes, I can create/modify/delete folders without causing the application to restart.
Not clear if this is the best solution -- Don't know if there will be unwanted side effects due to calling StopMonitoring.
也许有点晚了,但在应用程序的 wwwroot 之外的不同文件夹中存储和处理临时文件也可以解决问题。
Perhaps a bit late, but storing and handling your temp files in a different folder outside the wwwroot of your application also solves the problem.
默认情况下,asp.net 应用程序将在其虚拟目录中每 15 次更改文件时重新启动,这是为了抵消部分重新编译及其内存重量与整体性能的影响...您可以更改此行为,但内存使用量可能会增加,性能也会下降随着时间的推移而下降。
为此,请在编译元素上设置 numRecompilesBeforeAppRestart 属性, web.config 会有这样的 en 元素:
默认值为 15,您可以将其更改为您想要的任何值,阅读链接以获取更多信息。但是,这样做是有原因的,不建议将动态内容放在应用程序的虚拟目录中,最好将其放在应用程序的虚拟目录旁边或完全放在其他位置。
By default an asp.net application will restart every 15th time a file changes within it's virtual directory, this is to outweigh partial recompilations and their memory weight vs overall performance...you can change this behavior, but memory use may rise and performance will drop off over time.
To do this, set the numRecompilesBeforeAppRestart attribute on the compilation element, your web.config would have en element like this:
The default is 15, you can change it to whatever you want, read the link for more info. However, it's this way for a reason, it's not recommended to have your dynamic content inside the app's virtual directory, best to have it beside it or somewhere else entirely.
将
"fcnMode="Disabled"
添加到web.config
中的
设置会在 Web 根目录的内容被禁用时禁用 AppDomain 回收文件夹被更改。Adding
"fcnMode="Disabled"
to the<httpRuntime>
settings in theweb.config
disables AppDomain recycling when the contents of the web root folder are altered.启用 ASP.NET 运行状况监控 并查看事件日志以查看为什么AppDomain重新启动。
我敢打赌这是因为您使用的是网站项目,而不是 Web 应用程序项目。尝试使用 Web 应用程序项目重现这一点。
另外,您是否正在运行任何防病毒或索引软件?此类软件会通知何时创建和/或修改文件夹。
Enable ASP.NET Health Monitoring and look in the event log to see why the AppDomain restarted.
I bet this is because you've used a web site project, instead of a web application project. Try to reproduce this with a web application project.
Also, do you have any anti-virus or indexing software running? Such software notices when folders are created and/or modified.