仔細一看,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重啟,這也是必須保留的!