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

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

问题描述

更新 - 流程复制问题:

1)创建于 c进行网站项目:\\项目\\重启-演示

2)添加默认的web.config和伪aspx页面的 Test.aspx文件

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

3)地图IIS指向的根文件夹的 C:\\项目\\重启-演示

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

4)使用性能监视器,健康监测监控应用程序重新启动,在Global.asax中Application_End跟踪等。

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

5)在浏览器中://localhost/test.aspx

应用程序启动

6)创建新文件夹的 C:\\项目\\重启-DEMO \\ ASDF

6) Create new folder c:\projects\restart-demo\asdf

应用程序最终

7)浏览器://localhost/test.aspx

应用程序启动

8)重新命名文件夹 C:\\项目\\重启-DEMO \\ ASDF C:\\项目\\重启-DEMO \\ asdf1

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

应用程序最终

末更新

我们使用的是后端CMS生成在ASP.NET站点文件和文件夹。

We are using a back-end CMS to generate files and folders in an ASP.NET site.

用户能够创建/修改/删除文件,推动这些输出到Web场。

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.

请注意它并不需要像/ bin或/ APP_ code或者是特殊的文件夹。

Note it doesn't need to be a special folder like /bin or /App_Code either.

有什么办法prevent这种行为?

Is there any way to prevent this behavior?

这实在是阻碍业绩的原因有两个:

It is really hampering performance for two reasons:


  • 缓存被倾倒时,应用程序域重新启动

  • 应用域需要重新启动后重新建

推荐答案

这code能够解决这个问题,当加入的Application_Start()在Global.asax中:

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[] { }); 

<一个href=\"http://dotnetslackers.com/Community/blogs/haissam/archive/2008/11/12/disable-session-expiration-when-using-directory-delete.aspx\">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天全站免登陆