2011-08-25 45 views
1

我想設置一個簡單的HttpModule來處理我的單一登錄服務器之間的身份驗證。我已經包含了下面模塊的代碼。該模塊正在打我的SSO並正確認證;但是,在帶有表單的頁面上,回發事件不能正常發生(例如,即使POST發生,按鈕點擊事件不會被擊中等情況,isPostBack值始終爲false)。HttpModule打破PostBack事件

public sealed class MyAuthenticationModule : IHttpModule 
{  
    public void Init(HttpApplication context) 
    { 
     context.AuthenticateRequest += OnAuthenticateRequest; 
    } 
    public void Dispose() 
    { 
    } 

    public static void OnAuthenticateRequest(object sender, EventArgs e) 
    { 
     FormsAuthentication.Initialize(); 

     HttpContext context = HttpContext.Current; 
     HttpRequest request = context.Request; 
     HttpResponse response = context.Response; 

     // Validate the ticket coming back from the authentication server 
     if (!string.IsNullOrEmpty(request["ticket"])) 
     { 
      // I can include code for this if you want, but it appears to be 
      // working correct as whenever I get a ticket from my SSO it is processed 
      // correctly. I only get a ticket after coming from the SSO server and 
      // then it is removed from the URL so this only gets hit once. 
      MyAuthentication.ProcessTicketValidation(); 
     } 

     if (!request.IsAuthenticated) 
     { 
      // redirect to the login server 
      response.Redirect("https://sso.example.com/login.aspx" + "?" + "service=" + 
           HttpUtility.UrlEncode(context.Request.Url.AbsoluteUri), false); 
     } 
    } 
} 

編輯

我也想指出,如果我改變該行:

if (!string.IsNullOrEmpty(request["ticket"])) 

到:

if (!string.IsNullOrEmpty(request.QueryString["ticket"])) 

問題消失。

回答

0

您的回傳可能是否有重複的表單數據變量「ticket」?這似乎解釋了我的行爲。

除此之外,這條線是suspicous:

FormsAuthentication.Initialize();

FormsAuthentication類使用「Provider」模式,這意味着它是一個單例。你不應該重新初始化。當FormsAuthenticationModule 創建FormsAuthentication類的實例From the msdn documentation:

Initialize方法被調用。這種方法是 不打算從您的代碼中調用。

+0

感謝您的提示。這並沒有解決問題,但我會繼續並將其刪除。 – Kyle

+0

修改了我的答案以解決實際問題...請參閱第一行我想這就是我所有的... – Brett

+0

好的想法,但這不幸也不是問題。 – Kyle