2010-01-12 40 views
0

我正在使用ASP.Net的表單驗證工作。客戶端還會對服務器進行RESTfull調用(前端的ExtJS組件)。在.Net中驗證Cookie過期

我們正在使用自定義的HttpHandler進行服務調用。

我的問題是,無論何時何時身份驗證cookie過期,我的HttpHandler的ProcessRequest方法不會被調用,以便我檢查cookie的缺席並重定向用戶以再次登錄。

一個例子是用戶離開頁面然後在20分鐘後回來並點擊異步加載的下拉菜單。該應用程序只是掛起從來沒有得到我的處理程序。

有什麼想法?

回答

0

強烈建議閱讀本MSDN雜誌文章中標題爲「管道事件模型」的部分:Securely Implement Request Processing, Filtering, and Content Redirection with HTTP Pipelines in ASP.NET

簡而言之,認證在您的HttpHandler中將請求移交給ProcessRequest()之前就已完成。如果您需要處理這些情況下,您需要連接到管道的事件(如的BeginRequest或身份驗證的請求),並添加自己的處理程序,就像這樣:

public class EnableWebServicesModule : 
       IHttpModule 
    { 

    public void Init(HttpApplication app) 
    { 
     // register event handler 
     app.BeginRequest += new EventHandler(this.OnBeginRequest); 
    } 

    public void OnBeginRequest(object obj, EventArgs ea) 
    { 
     // Check if security works here by looking for the cookie or 
     // the user context. 

    } 

    ... 
} 

進一步的閱讀在這個迷人的和令人興奮的話題,check Rich Strahl's walkthrough: A low-level Look at the ASP.NET Architecture