asp.net 刪除項目文件/文件夾IIS重啟,Session丟失問題
更新時間:2011年12月23日 00:21:37 作者:
最近在做一個項目,涉及到大量文件中轉(先上傳到本項目的某個文件夾中,在移動到FTP中),后面發(fā)現(xiàn)每次一刪除文件之后在做操作都會提示未登錄,剛開始以為是WebService Session丟失問題,后面發(fā)現(xiàn)緩存也更新了
仔細一看,SSO返回的ticket也不相同,才發(fā)現(xiàn)原來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 Core讀取Request.Body的正確方法
相信大家在使用ASP.NET Core進行開發(fā)的時候,肯定會涉及到讀取Request.Body的場景,畢竟我們大部分的POST請求都是將數(shù)據(jù)存放到Http的Body當中,本文就介紹一下ASP.NET Core讀取Request.Body,感興趣的可以了解一下2021-05-05
asp.net開發(fā)中常見公共捕獲異常方式總結(附源碼)
這篇文章主要介紹了asp.net開發(fā)中常見公共捕獲異常方式總結,結合實例形式較為詳細的分析了asp.net捕獲異常的相關技巧,并提供了完整的實例代碼供讀者下載參考,需要的朋友可以參考下2015-11-11
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉化無效
數(shù)據(jù)庫 數(shù)據(jù)類型float到C#類型decimal, float數(shù)據(jù)類型轉化無效的解決方法2009-07-07

