asp.net 删除项目文件/文件夹IIS重启,Session丢失问题
时间:2021-01-22 12:24:48|栏目:.NET代码|点击: 次
仔细一看,SSO返回的ticket也不相同,才发现原来IIS重启了,最后解决方案如下:
新建一个类继承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() { }
}
随后在Web.Config中加入Module配置
<!--解决删除项目文件/文件夹引起的IIS重启-->
<add name="stopAppDomainRestartOnFolderDelete" type="DeployAssistant.Facade.Web.StopAppDomainRestartOnFolderDeleteModule,DeployAssistant.Facade"/>
这样每次再删除文件/文件夹AppDomain都不会重启了,Session也不会丢失了。世界也变得更美好了!
PS:Web.Config和bin文件夹下的改动依然会让Web重启,这也是必须保留的!
新建一个类继承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() { }
}
随后在Web.Config中加入Module配置
复制代码 代码如下:
<!--解决删除项目文件/文件夹引起的IIS重启-->
<add name="stopAppDomainRestartOnFolderDelete" type="DeployAssistant.Facade.Web.StopAppDomainRestartOnFolderDeleteModule,DeployAssistant.Facade"/>
这样每次再删除文件/文件夹AppDomain都不会重启了,Session也不会丢失了。世界也变得更美好了!
PS:Web.Config和bin文件夹下的改动依然会让Web重启,这也是必须保留的!
上一篇:ASP.Net MVC+Data Table实现分页+排序功能的方法
栏 目:.NET代码
本文标题:asp.net 删除项目文件/文件夹IIS重启,Session丢失问题
本文地址:http://www.codeinn.net/misctech/49049.html