Anti-virus scans the .Net deployed folders. Because of this, application gets logged out frequently for the customers.
Requires lot of approval in order to get exemption at the folder level for the project. So, I used below code:
//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[] { });
Used this article for above code.
Code works fine for a day. But, problem starts again next day. So, I replace the deployed folder again. Then, everything works fine.
Would like to know what causes the problem starts again. What should be done to not face again.
Also, how to stop scanning all the folders where application deployed. Because, application has custom folders where output files will be saved. This also should not be scanned.
Thanks in advance!
Thanks a lot to @zaitsman for his help
With his help, modified the code like below
Hope code would help someone
However, I initially received null error when accessing
monitor_dirMonAppPathInternal
object. If anyone could say when the object will not be null, it would be helpfulThis is because you have your app pool being recycled by IIS (which is a good thing, because it will prevent any memory leaks you might have).
When this happens,
Application_start
is no longer called: https://msdn.microsoft.com/en-us/library/ms178473.aspx (same applies for IIS 7.0+)What you should do is set up a
static
field in yourGlobal.asax
and on eachApplication_AcquireRequestState
check if it is set totrue
. if not, run the code you posted, and then set the field to true.This will ensure that the code will only ever run once per your worker process being alive.
Since there are only 2 monitors inside the
FileChangesMonitor
class, you simply need to stop monitoring on both, so the full listing would be: