当创建,重命名或删除文件夹时,ASP.NET重新启动 [英] ASP.NET restarts when a folder is created, renamed or deleted

查看:259
本文介绍了当创建,重命名或删除文件夹时,ASP.NET重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE - 要复制问题的进程

1)在 c:\projects\ restart-demo

2)添加默认的web.config和一个dummy aspx页面 test.aspx

2) Add default web.config and a dummy aspx page test.aspx

3)将IIS映射到根文件夹 c:\projects\restart-demo

3) Map IIS to point to the root folder c:\projects\restart-demo

4)使用perfmon监控应用程序重新启动,运行状况监视,在global.asax Application_End等中跟踪

4) Monitor application restarts using perfmon, health monitoring, tracking in global.asax Application_End, etc.

5)在浏览器中请求页面 http://localhost/test.aspx

5) Request page in browser http://localhost/test.aspx

应用程序启动

6)创建新文件夹 c:\projects\restart-demo \asdf

应用程序结束

7)在浏览器中请求页面 http://localhost/test.aspx

7) Request page in browser http://localhost/test.aspx

应用程序启动

application start

8)将文件夹 c:\projects\restart-demo \asdf 重命名为 c:\projects\restart-demo\ asdf1

8) Rename folder c:\projects\restart-demo\asdf to c:\projects\restart-demo\asdf1

应用程式结束

/ strong>

end update

我们使用后端CMS在ASP.NET网站中生成文件和文件夹。

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.

我们注意到一个问题:


当用户创建,重命名或删除文件夹时,会导致App
域重新启动。因此,
会话,缓存等都会丢失。

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.

注意,它不需要是

有什么方法可以防止这种行为吗?

Is there any way to prevent this behavior?


  • 应用程式网域重新启动时,系统会转储缓存

  • 应用程式网域需要在重新启动后重新构建

推荐答案

此代码似乎可以解决问题,添加到Global.asax中的Application_Start():

This code appears to resolve the issue, when added to Application_Start() in Global.asax:

PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public |  BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { }); 

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.

不清楚这是否是最佳解决方案 - 不知道是否会由于调用StopMonitoring而产生不必要的副作用。

Not clear if this is the best solution -- Don't know if there will be unwanted side effects due to calling StopMonitoring.

这篇关于当创建,重命名或删除文件夹时,ASP.NET重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆