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

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

问题描述

UPDATE -- 复制问题的过程:

1) 在 c:\projects\restart-demo

2) 添加默认的 web.config 和一个虚拟的 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) 在 global.asax Application_End 中使用 perfmon、健康监控、跟踪等监控应用程序重启

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

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

应用启动

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

申请结束

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

应用启动

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

申请结束

结束更新

我们正在使用后端 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.

我们注意到的一个问题:

One problem we have noticed:

当用户创建、重命名或删除文件夹时,会导致 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.

请注意,它也不需要是像/bin 或/App_Code 这样的特殊文件夹.

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:

  • 当应用域重新启动时缓存被转储
  • 重启后需要重新构建应用域

推荐答案

当添加到 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天全站免登陆