2013-05-18 25 views
2

我在.aspx頁面中使用緩存(ASP.NET 4)是這樣的:排除緩存,如果特定的URL參數存在

<%@ OutputCache Duration="100000" VaryByParam="CategoryID" %> 

,任何東西都很好,直到當頁面URL有traceid我需要的不要不使用任何緩存。

那麼當URL參數中存在'traceid'時,有什麼辦法排除緩存嗎? 有什麼建議嗎?

+0

無法通過OutputCache指令做到這一點。你將不得不完全在代碼上實現它。 – Icarus

+0

@伊卡洛斯好的,我怎麼能這樣做?任何建議? – Saeid

+0

通過設置適當的響應標頭,這與OutputCache指令的功能完全相同。我是從手機寫的,所以我很難寫一個完整的工作示例,但我會提供僞代碼... – Icarus

回答

0

我還發現東西是爲我工作:

protected override void OnPreInit(EventArgs e) 
    { 
     if (HttpContext.Current.Request.QueryString.AllKeys.Contains("traceid")) 
      HttpContext.Current.Response.CacheControl = "no-cache"; 
     base.OnPreInit(e); 

    } 
0
if(Requesq.QueryString["trace_id"]== null) 
{ 
    Response.AddHeader("Cache-Control", "max-age=86400"); 
    //and any other header that may be needed to instruct a browser that it should cache the response 
    Response.AddHeader("Vary",... 
} 

我會火起來的開發者工具在Chrome中(命中F12)和分析所有的當前頁面上發送的響應報頭,並使用這些,因爲你需要在每個響應設置的標頭的一個例子。這樣,當查詢字符串中包含trace_id時,不會添加這些標頭。

相關問題