2013-06-12 154 views
4

我通常會避免進程內會話狀態,直到這個最近的項目。我想我遇到了一個問題,在發生未處理的異常之後狀態會丟失。ASP.NET會話狀態異常後丟失

這本身就很奇怪,因爲請求上下文中的異常不會影響工作進程。它可能是後臺線程或回調等的異常,但是,這是一個簡單的網站,沒有什麼奇特的事情發生。

會話ID保持不變,Session_Start不會在後續請求中調用(因此WP未被回收)。

我有相當多的日誌記錄啓用,它的平原看到我從數據層得到一個異常,其HttpException在HttpUnhandleException中,然後當我瀏覽主頁後立即請求記錄一個警告關於缺少的狀態。

更糟。這不會發生在我的開發盒(IIS Express)上,僅在QA中。

編輯:

這裏是日誌的一大塊:

2013-06-12 13:44:29,975 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET An unhandled exception occurred in the web application. The full exception will be unrolled below. 
2013-06-12 13:44:30,897 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET Exception.Type: HttpUnhandledException 
Exception.Source: System.Web 
Exception.Message: Exception of type 'System.Web.HttpUnhandledException' was thrown. 
Exception.StackTrace: at System.Web.UI.Page.HandleError(Exception e) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.HttpContext.InvokeCancellableCallback(WaitCallback callback, Object state) 
    at System.Web.UI.Page.LegacyAsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, Object extraData) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

    Exception.Type:  HttpException 
    Exception.Source:  CompanyNameProductName.MvcCoreApp 
    Exception.Message:  An error was reported by the data layer: 0Image not found1-10.1007_978-1-4471-4294-2_21-16 
    Exception.StackTrace:  at CompanyName.CompanyNameProductName.imagedetail.Page_Load(Object sender, EventArgs e) in c:\DATA\Git\ProductName\CompanyNameProductNameMvc\imagedetail.aspx.cs:line 55 
    at System.Web.UI.Control.LoadRecursive() 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 


2013-06-12 13:45:07,913 [25] DEBUG StandardPage 100.100.100.100 pxtgn GET Initializing page 'default_aspx' for GET with query string: 
2013-06-12 13:45:07,913 [25] ERROR StandardPage 100.100.100.100 pxtgn GET No User instance in session state. Check the log for signs that the session was started properly since a User object should aways exist in session state, setup via session start events in ASP.NET. 

最後一行顯示丟失的狀態條件。 pxtgn是會話ID中的前5個字符。我打了一個頁面,我知道數據層會關於不存在的圖像ID。然後,我接下來打的任何頁面都會導致我的檢查記錄缺少狀態的問題。檢查和狀態參考位於母版頁的代碼中,所以我可以打任何頁面查看問題。這也意味着自定義錯誤頁面不起作用 - 這就是我發現錯誤的方式。

我已經在檢查後添加了一個Session.Abandon(),並回復了一個500讓我離開監獄,但它的一個奇怪的問題。我是新來的代碼庫,我想我到處檢查會話被清除或狀態被覆蓋。

+0

如果你在'Application_Start'中放置一個斷點,會發生什麼?這是否再次被調用? –

+0

該網站的負載是否平衡?你使用Webgarden嗎? –

+0

@Darin - 它不叫。這裏也有記錄,似乎WP保持不變。 –

回答

-3

1線程被破壞 2個異步環境

使用的HttpContext作爲參數 不System.Web程序。 * * .httpcontext

+5

請付出更多努力回答。用標點符號寫出整個句子,確保格式正確。最重要的是,請解釋*爲什麼*這回答了這個問題。 –