ASP.NET restarts when a folder is created, renamed or deleted

前端 未结 5 821
失恋的感觉
失恋的感觉 2020-12-01 08:15

UPDATE -- process to replicate issue:

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

2) Add default web.config a

相关标签:
5条回答
  • 2020-12-01 08:51

    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.

    0 讨论(0)
  • Perhaps a bit late, but storing and handling your temp files in a different folder outside the wwwroot of your application also solves the problem.

    0 讨论(0)
  • 2020-12-01 09:01

    Enable ASP.NET Health Monitoring and look in the event log to see why the AppDomain restarted.


    I bet this is because you've used a web site project, instead of a web application project. Try to reproduce this with a web application project.

    Also, do you have any anti-virus or indexing software running? Such software notices when folders are created and/or modified.

    0 讨论(0)
  • 2020-12-01 09:06

    Adding "fcnMode="Disabled" to the <httpRuntime> settings in the web.config disables AppDomain recycling when the contents of the web root folder are altered.

    0 讨论(0)
  • 2020-12-01 09:07

    By default an asp.net application will restart every 15th time a file changes within it's virtual directory, this is to outweigh partial recompilations and their memory weight vs overall performance...you can change this behavior, but memory use may rise and performance will drop off over time.

    To do this, set the numRecompilesBeforeAppRestart attribute on the compilation element, your web.config would have en element like this:

    <configuration>
      <system.web>
        <compilation numRecompilesBeforeAppRestart="15">
    

    The default is 15, you can change it to whatever you want, read the link for more info. However, it's this way for a reason, it's not recommended to have your dynamic content inside the app's virtual directory, best to have it beside it or somewhere else entirely.

    0 讨论(0)
提交回复
热议问题