asp.net delete project file and folder IIS restart Session missing problem
- 2020-05-16 06:54:04
- OfStack
Look carefully 1, SSO returned ticket is not the same, only to find that the original IIS has been restarted, the final solution is as follows:
Create a new class that inherits IHttpModule
The Module configuration is then added to Web.Config
Every time you delete a file/folder, AppDomain will not be rebooted, and Session will not be lost. The world is a better place!
Changes to PS: Web.Config and bin folders will still cause Web to restart, which must be kept!
Create a new class that inherits 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() { }
}
The Module configuration is then added to Web.Config
<!-- Resolve to delete project files / Folder caused IIS restart -->
<add name="stopAppDomainRestartOnFolderDelete" type="DeployAssistant.Facade.Web.StopAppDomainRestartOnFolderDeleteModule,DeployAssistant.Facade"/>
Every time you delete a file/folder, AppDomain will not be rebooted, and Session will not be lost. The world is a better place!
Changes to PS: Web.Config and bin folders will still cause Web to restart, which must be kept!