FCMode + 'dir change or directory rename'

Last post 01-06-2009 2:27 PM by hitchhiker999. 5 replies.

Sort Posts:

  • FCMode + 'dir change or directory rename'

    08-26-2008, 12:37 PM
    • Member
      point Member
    • hitchhiker999
    • Member since 08-26-2008, 12:30 PM
    • Posts 9

    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?

  • Re: FCMode + 'dir change or directory rename'

    08-26-2008, 2:42 PM
    Answer
    • Member
      point Member
    • hitchhiker999
    • Member since 08-26-2008, 12:30 PM
    • Posts 9

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

  • Re: FCMode + 'dir change or directory rename'

    08-26-2008, 2:47 PM
    • Star
      11,036 point Star
    • Bruce L
    • Member since 02-08-2007, 6:53 PM
    • Posts 1,859

    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.

    Bruce
    DiscountASP.NET - ASP.NET Hosting Experts
    Voted 2009 "Best ASP.NET Hosting" by asp.netPRO Magazine
    Win2008/IIS7.0, ASP.NET 2.0/3.5 SP1, MVC, AJAX, Silverlight, SQL 2008/2005
  • Re: FCMode + 'dir change or directory rename'

    08-27-2008, 4:06 AM
    • Member
      point Member
    • hitchhiker999
    • Member since 08-26-2008, 12:30 PM
    • Posts 9

    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.

  • Re: FCMode + 'dir change or directory rename'

    01-04-2009, 1:18 AM
    • Member
      2 point Member
    • bernesto
    • Member since 01-04-2009, 4:58 AM
    • Posts 1

    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.

  • Re: FCMode + 'dir change or directory rename'

    01-06-2009, 2:27 PM
    • Member
      point Member
    • hitchhiker999
    • Member since 08-26-2008, 12:30 PM
    • Posts 9

     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!

     

Page 1 of 1 (6 items)