Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

content management system - ASP.NET restarts when a folder is created, renamed or deleted

UPDATE -- process to replicate issue:

1) Create a website project at c:projects estart-demo

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

3) Map IIS to point to the root folder c:projects estart-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 estart-demoasdf

application end

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

application start

8) Rename folder c:projects estart-demoasdf to c:projects estart-demoasdf1

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...