2010-07-05 115 views

回答

9

是的,你可以的,如果你願意創建自己的配置部分:http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

在你的配置部分裝上去一樣,

<cachingConfig> 
    <path>/Navigation/Menu.aspx</path> 
    <path>/Target/Console.aspx</path> 
    <path>/Target/Charting/Chart.aspx</path> 
</cachingConfig> 

如果你願意,你可以添加更多的屬性,如持續時間。

然後,在您的網頁page_Init方法,檢查配置部分,並調用以下酌情:

Response.Cache.SetCacheability(HttpCacheability.NoCache) 

編輯:提示:把初始化代碼中的一個基類,你的頁面繼承,所以它只是一個地方。

11
<!-- In the page itself --> 
<%@ OutputCache Location="None" %> 

或者

// In the code-behind 
Response.Cache.SetCacheability(HttpCacheability.NoCache) 

不幸的是,它必須在頁面內完成。有沒有簡單的方法來從web.config做到這一點。欲瞭解更多信息,請訪問:

MSDN - Setting the Cacheability of a Page

7
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetNoStore();