2010-09-17 26 views
2

我有一個.net 3.5網站,它使用Windows身份驗證,並在我的基礎主頁類的預渲染中使用元標記過期會話。如何防止會話在使用AJAX時過期?

protected override void OnPreRender(EventArgs e) 
{ 
    base.OnPreRender(e); 
    if (Response.ContentType == "text/html") 
     this.Page.Header.Controls.Add(new LiteralControl(
      String.Format("<meta http-equiv='refresh' content='{0};url={1}'>", 
      SessionLengthMinutes * 60, SessionExpireDestinationUrl))); 
} 

這非常適用於那些充滿後背上的網頁。但是,在我的應用程序中有幾個頁面,用戶在更新面板中執行了大量工作。我公司的政策是暫停15分鐘。這意味着,在更新面板頁面內工作15分鐘後,用戶將被重定向到應用程序啓動頁面。

有沒有辦法在異步回發中重置或擴展元標記?或者更好的方法來完成這一切?

回答

1

完成此操作的更好方法是使用javascript。如果您的網頁已添加書籤,這將防止與元刷新相關的問題。

在發生的網頁META REFRESH使用此javascript:

<script type="text/javascript"> 
    var _timerID = setTimeout("window.location='splash-url'", 900000); //15 mins 
</script> 

當您從更新面板的請求使用此javascript:

<script type="text/javascript"> 
    clearTimeout(_timerID); 
    _timerID = setTimeout("window.location='splash-url'", 900000); //15 mins 
</script> 
0

在過去,我已經使用了的WebMethod(EnableSession =真)屬性上,以響應AJAX方法的調用