2013-06-25 17 views
0

我有一個類繼承我的所有網頁來檢查會話超時,然後重定向到登錄頁面這裏是代碼地址跳過第二個查詢參數在HttpContext.Current.Request.Url.AbsoluteUri

public class WMUserBase:System.Web.UI.Page 
{ 
    public WMUserBase() 
    { 

    } 
    protected override void OnLoad(System.EventArgs e) 
    { 
     CheckSecurity(); 
     base.OnLoad(e); 
    } 
    public virtual void CheckSecurity() 
    { 
     if (Session["WMuserId"] == null || Session["WMuserId"].ToString() == "") 
     { 
      Response.Redirect("Login.aspx?ReturnUrl=" + HttpContext.Current.Request.Url.AbsoluteUri); 
     } 
    } 
} 

每頁面繼承這個類,如果會話超時,然後頁被重定向到登錄頁面,現在我用
Response.Redirect("Login.aspx?ReturnUrl=" + HttpContext.Current.Request.Url.AbsoluteUri); 但如果我的查詢字符串在AbsoluteUril用於如http://localhost/mala3ibnav2/WeeklyManager/TeamSetup.aspx?Gid=MTQ=&Mid=Mg== 兩個參數&中秋節是Mg ==有時跳過並非總是如此。
這裏是登錄頁面登錄按鈕單擊事件的代碼

if(string.IsNullOrEmpty(ReturnUrl)) 
       { 
        Response.Redirect("Default.aspx"); 
       } 
       else 
       { 
        Response.Redirect(ReturnUrl); 
       } 

現在爲什麼第二個參數的查詢字符串跳過,還有什麼我應該是用HttpContext.Current.Request.Url.AbsoluteUri

代替
+0

您需要編碼URL,尤其是&符號標誌。如果你檢查網址,&不應該在那裏找到,但編碼 – codingbiz

+0

感謝您的幫助,讓我試試看 – skhurams

回答

2

你必須編碼網址:

Response.Redirect("Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri)); 

如果您正在使用的形式autentication,你可以驗證超時設置爲比會話超時少一分鐘。然後,您不必自己編寫代碼,因爲在超時過期後,ASP.NET會自動將用戶重定向到登錄頁面。

相關問題