在asp.net中关闭Global.asax中的文件/文件夹更改 [英] Turn off Files/Folder changes in Global.asax in asp.net
问题描述
防病毒扫描.Net部署的文件夹。因此,应用程序会经常为客户注销。
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.
提前致谢!
推荐答案
非常感谢@zaitsman为他的帮助
Thanks a lot to @zaitsman for his help
在他的帮助下,修改了如下代码
With his help, modified the code like below
<%@ import namespace="System.Reflection"%>
private static bool hasRemovedFoldersFromMonitoring = false;
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if (!hasRemovedFoldersFromMonitoring)
{
PropertyInfo fcmPi = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
object o = fcmPi.GetValue(null, null);
FieldInfo fi_dirMonSubdirs = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor_dirMonSubdirs = fi_dirMonSubdirs.GetValue(o);
MethodInfo m_dirMonSubdirs = monitor_dirMonSubdirs.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m_dirMonSubdirs.Invoke(monitor_dirMonSubdirs, new object[] { });
FieldInfo fi_dirMonAppPathInternal = o.GetType().GetField("_dirMonAppPathInternal", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor_dirMonAppPathInternal = fi_dirMonAppPathInternal.GetValue(o);
if (monitor_dirMonAppPathInternal != null)
{
MethodInfo m_dirMonAppPathInternal = monitor_dirMonAppPathInternal.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m_dirMonAppPathInternal.Invoke(monitor_dirMonAppPathInternal, new object[] { });
}
hasRemovedFoldersFromMonitoring = true;
}
}
希望代码可以帮助某人
但是,在访问 monitor_dirMonAppPathInternal
对象时,我最初收到null错误。如果有人可以说对象何时不为null,那将是有帮助的
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 helpful
这篇关于在asp.net中关闭Global.asax中的文件/文件夹更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!