Recently I am working on a project that involves transferring a large number of files (first upload to a folder of the project and move it to FTP ), after each file is deleted, the system will prompt that the file is not logged on. At first, the WebService session is lost, and the cache is updated later. After careful consideration, the ticket returned by SSO is also different, and the original IIS is restarted. The final solution is as follows:
Create a class that inherits the ihttpmodule
/// <summary>
/// Stops the ASP.NET AppDomain being restarted (which clears
/// Session state, Cache etc.) whenever a folder is deleted.
/// </summary>
public class StopAppDomainRestartOnFolderDeleteModule : IHttpModule
{
private static bool DisableFCNs = false;
public void Init(HttpApplication context)
{
if (DisableFCNs) return;
PropertyInfo p = typeof(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[] { });
DisableFCNs = true;
}
public void Dispose() { }
}
Then add module configuration in Web. config.
<! -- Solve IIS restart caused by deleting project files/folders -->
<Add name = "stopappdomainrestartonfolderdelete" type = "deployassistant. facade. Web. stopappdomainrestartonfolderdeletemodule, deployassistant. Facade"/>
In this way, the appdomain of the file/folder will not be restarted and the session will not be lost. The world has become better!
PS: changes in the web. config and bin folders will still restart the web, which must be retained!
Recently I am working on a project that involves transferring a large number of files (first upload to a folder of the project and move it to FTP ), after each file is deleted, the system will prompt that the file is not logged on. At first, the WebService session is lost, and the cache is updated later. After careful consideration, the ticket returned by SSO is also different, and the original IIS is restarted. The final solution is as follows:
Create a class that inherits the ihttpmodule
/// <summary>
/// Stops the ASP.NET AppDomain being restarted (which clears
/// Session state, Cache etc.) whenever a folder is deleted.
/// </summary>
public class StopAppDomainRestartOnFolderDeleteModule : IHttpModule
{
private static bool DisableFCNs = false;
public void Init(HttpApplication context)
{
if (DisableFCNs) return;
PropertyInfo p = typeof(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[] { });
DisableFCNs = true;
}
public void Dispose() { }
}
Then add module configuration in Web. config.
<! -- Solve IIS restart caused by deleting project files/folders -->
<Add name = "stopAppDomainRestartOnFolderDelete" type = "DeployAssistant. Facade. Web. StopAppDomainRestartOnFolderDeleteModule, DeployAssistant. Facade"/>
In this way, the AppDomain of the file/folder will not be restarted and the Session will not be lost. The world has become better!
PS: changes in the Web. Config and bin folders will still restart the Web, which must be retained!