asp.net 删除项目文件/文件夹IIS重启,Session丢失问题
程序员文章站
2024-03-06 12:15:38
仔细一看,sso返回的ticket也不相同,才发现原来iis重启了,最后解决方案如下: 新建一个类继承ihttpmodule 复制代码 代码如下: ///
仔细一看,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重启,这也是必须保留的!