2010-09-22 61 views
1

我在處理Authentication_Request的其中一個模塊中設置自定義主體。然後我將它設置爲HttpContext.User。這設置我的HttpContext.User和Thread.CurrentPrincipal。現在,當發生錯誤並且customErrors部分包含「ResponseRewrite」時,Thread.CurrentPrincipal在我的ASPX錯誤頁面上重置爲通用主體,但是我的HttpContext.User仍包含我的自定義主體。如果customErrors部分包含「ResponseRedirect」,則不會發生這種情況。這是預期的行爲?ASP .NET:當customErrors包含redirectMode =「ResponseRewrite」時,Thread.CurrentPrincipal會丟失

+0

這個標籤是否正確,聽起來不像一個ASP問題。 ASP.NET? – 2010-09-22 19:12:37

+0

oops。剛剛更新了標籤。 – Eric 2010-09-23 00:50:08

回答

0

我懷疑服務器正在旋轉一個單獨的線程來執行錯誤頁面。您可以通過將以下內容放入Global.asax來重置它(Thread.CurrentPrincipal)。

protected void Application_AuthenticateRequest(object sender, EventArgs e) { 
     Thread.CurrentPrincipal = HttpContext.Current.User; 
    } 

此行將確保兩個請求都與您的應用程序同步。