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"]))
問題消失。
感謝您的提示。這並沒有解決問題,但我會繼續並將其刪除。 – Kyle
修改了我的答案以解決實際問題...請參閱第一行我想這就是我所有的... – Brett
好的想法,但這不幸也不是問題。 – Kyle