2010-09-11 38 views
0

每次進行重定向時,我想清除我的主頁上的佔位符控件。 如何在代碼隱藏中實現這一目標?檢測到響應重定向的主頁

我可以檢查最後一次保存的網址和當前的網址是否匹配, 但這是一個真正的臨時解決方案,我不想去。

喜歡的東西[IF(//頁轉到檢測){//做一些事情}

+0

如果您在重定向的控制,你可以一個標誌追加到查詢字符串,表明這是一個重定向並有查詢字符串參數母版頁檢查。 – 2010-09-11 19:52:29

回答

1

我只想轉儲標誌爲會話當你做一個重定向。檢查主頁中每個負載上的標誌並將其清除,以便後續請求不會不必要地檢測到它。也許你可以創建一個重定向幫助類來集中設置標誌。

if (Session["RedirectFlag"] != null && (bool)Session["RedirectFlag"]) 
{ 
    // clear your placeholder 
    Session.Remove("RedirectFlag"); // clear the flag 
} 

..

public static class HttpResponseExtension 
{ 
    public static void RedirectWithFlag(this HttpResponse response, string url) 
    { 
     response.RedirectWithFlag(url, true); 
    } 

    public static void RedirectWithFlag(this HttpResponse response, string url, bool endResponse) 
    { 
     System.Web.HttpContext.Current.Session["RedirectFlag"] = true; 
     response.Redirect(url, endResponse); 
    } 
}