簡體   English   中英

ASP.NET:文件夾刪除后會話已過期

[英]ASP.NET: Session expired after folder delete

我在將代碼移動到另一個文件夾並刪除ASP.NET應用程序中以前的文件夾和文件的代碼中。 刪除文件夾后,我的會話已過期。 如何限制會話值過期。

非常真實 發生這種情況是因為刪除操作更改了ASP.NET應用程序的文件夾樹,這迫使應用程序回收。 看到這里: http : //www.geekays.net/post/2008/10/14/ASPNET-webdomain-recycle-on-subfolder-changes.aspx

在Global.asax頁面內使用以下代碼

void Application_Start(object sender, EventArgs e) 
{
    System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
    object o = p.GetValue(null, null);
    System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
    object monitor = f.GetValue(o);
    System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    m.Invoke(monitor, new object[] { }); 
}

請在globle.asax的Session_End方法內編寫目錄刪除代碼

void Session_End(object sender, EventArgs e)
{
    SampleDelete();
}
private static void SampleDelete()
{
    try
    {
        string samplesss = AppDomain.CurrentDomain.BaseDirectory + "\\temp";
        string[] array1 = System.IO.Directory.GetDirectories(samplesss);
        try
        {
            foreach (string item in array1)
            {
                System.IO.Directory.Delete(item, true);
            }
        }
        catch (Exception ex)
        { }
    }
    catch (Exception ex)
    {
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM