I'm having trouble with disabling File Change Notification on my .NET 2 / 3.5 webserver. I have an app that removes directories once in a while, every time that happens I get 'dir change or directory rename HostingEnvironment initiated shutdown'
-Is it in the wrong place, when I delete a directory the site still recycles?
Also:
-Is there any way to switch of FCN programatically via my global.asax or any other method?
-If so would setting up my own FCN service (that just monitors certain config files) and using 'System.Web.HttpRuntime.UnloadAppDomain();' be identical to the native one?
The above code, when attached to my global.asax (app start), stopped file change notifications only on the sub dirs - it was the perfect solution as touching web.config or /bin/ still correctly causes a refresh.
Thanks for the awesome piece of code. In my tests, without the code, deleting a directory causes the application to restart, with the code it does not. Touching the web.config or the bin still causes the application to restart.
Yep, that's the experience I have.. I've now been using it since I posted it and it's been working flawlessly..
I can't believe this isn't mentioned more, considering the nature of most web apps these days, this is a serious issue - app restarts cause many issues eg: a user uploads an image and the temp file is located within the app dir (which it may be for a lot
of people) the app loses it's state!
Thanks for posting on this. We had the same issue. We developed a control as a webbased file explorer. In testing, everytime the user deleted a folder, session was killed. This post, your code, fixed our issues.
hitchhiker999
Member
14 Points
13 Posts
FCMode + 'dir change or directory rename'
Aug 26, 2008 04:37 PM|LINK
I'm having trouble with disabling File Change Notification on my .NET 2 / 3.5 webserver. I have an app that removes directories once in a while, every time that happens I get 'dir change or directory rename HostingEnvironment initiated shutdown'
I put this key in, as instructed - then rebooted.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET]
"FCNMode"=dword:00000001
-Is it in the wrong place, when I delete a directory the site still recycles?
Also:
-Is there any way to switch of FCN programatically via my global.asax or any other method?
-If so would setting up my own FCN service (that just monitors certain config files) and using 'System.Web.HttpRuntime.UnloadAppDomain();' be identical to the native one?
hitchhiker999
Member
14 Points
13 Posts
Re: FCMode + 'dir change or directory rename'
Aug 26, 2008 06:42 PM|LINK
I found this somewhere on your site, which solved it:
//FIX disable AppDomain restart when deleting subdirectory
//This code will turn off monitoring from the root website directory.
//Monitoring of Bin, App_Themes and other folders will still be operational, so updated DLLs will still auto deploy.
System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); m.Invoke(monitor, new object[] { });
Bruce L
All-Star
18102 Points
2841 Posts
Re: FCMode + 'dir change or directory rename'
Aug 26, 2008 06:47 PM|LINK
I think the path of the registry key is correct.
Have you tried restart IIS and see if the new setting takes?
I don't believe you can switch off file change notification programatically.
http://www.discountASP.NET
hitchhiker999
Member
14 Points
13 Posts
Re: FCMode + 'dir change or directory rename'
Aug 27, 2008 08:06 AM|LINK
I had rebooted actually, but it's fine now..
The above code, when attached to my global.asax (app start), stopped file change notifications only on the sub dirs - it was the perfect solution as touching web.config or /bin/ still correctly causes a refresh.
bernesto
Member
2 Points
1 Post
Re: FCMode + 'dir change or directory rename'
Jan 04, 2009 05:18 AM|LINK
Thanks for the awesome piece of code. In my tests, without the code, deleting a directory causes the application to restart, with the code it does not. Touching the web.config or the bin still causes the application to restart.
hitchhiker999
Member
14 Points
13 Posts
Re: FCMode + 'dir change or directory rename'
Jan 06, 2009 06:27 PM|LINK
Yep, that's the experience I have.. I've now been using it since I posted it and it's been working flawlessly..
I can't believe this isn't mentioned more, considering the nature of most web apps these days, this is a serious issue - app restarts cause many issues eg: a user uploads an image and the temp file is located within the app dir (which it may be for a lot of people) the app loses it's state!
ibolden
Member
2 Points
1 Post
Re: FCMode + 'dir change or directory rename'
Feb 12, 2010 02:59 PM|LINK
hitchhiker999,
Thanks for posting on this. We had the same issue. We developed a control as a webbased file explorer. In testing, everytime the user deleted a folder, session was killed. This post, your code, fixed our issues.
Just wanted to say thanks.
~Ian
Session .ASPX
ManicStudio
Member
30 Points
29 Posts
Re: FCMode + 'dir change or directory rename'
Feb 22, 2010 11:25 AM|LINK
This only works in full trust. What about shared hosting server that runs in medium trust level?
vindy
Member
172 Points
33 Posts
Re: FCMode + 'dir change or directory rename'
Aug 31, 2010 02:58 PM|LINK
Hi Hitchhiker999
the following code returns null f.GetValue(o); any idea why this is happening
hitchhiker999
Member
14 Points
13 Posts
Re: FCMode + 'dir change or directory rename'
Aug 31, 2010 09:22 PM|LINK
Hey Vindy - no idea, but I assume it's either due to Trust levels or Framework version?