Application Restart for folder deleted,added,updat

2019-03-06 04:00发布

Modifying, adding, or deleting certain types of files within the application's known folders will cause the application to restart.But when Log file in application is updated,why application is not restart. Then

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

With these changes, I can create/modify/delete folders without causing the application to restart. But this code is for all application's known folders.I want to know is for one folder without causing the application restart.

1条回答
时光不老,我们不散
2楼-- · 2019-03-06 04:08

Your problem is because as soon as you modify, or delete any file from the applications directory, it is causing appDomain restart in order to load the changes. You got 4 options as far as I could look for:

  1. Disable directory monitoring, which you have already tried.
  2. Create a Virtual directory under the application and point this to a folder outside the application folder. Move the content that needs to be changed to this folder and can make changes.
  3. Use out of process session.
  4. Modify the registry to disable monitoring as given (Not recommended):

Registry information

loadTOCNode(3, 'resolution'); HKLM\Software\Microsoft\ASP.NET\FCNMode

The following table lists possible values for the FCNMode DWORD value and the behavior that is associated with each value.

Value Behavior Does not exist This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 0 or greater than 2 This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.

1 The application will disable File Change Notifications (FCNs). [:)].

2 The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory.

The above method is take from here

Also, you can go through the following links for more information:

Well, this might be able to help with your issue, I could not find out anything about stopping the appDomain change monitoring for a specific folder. Either it would monitor the changes or not. Hope this helps. Cheers.

查看更多
登录 后发表回答