2011-10-31 189 views
0

環境:IIS 7,.NET 4.0覆蓋web.config的設置

在我們的應用程序的web.config文件,它有這個節:

<system.webServer> 
    <httpProtocol> 
    <customHeaders> 
    <add name="cache-control" value="no-cache" /> 
    </customHeaders> 
    </httpProtocol> 
</system.webServer> 

我們的大多數應用程序的需要無緩存,但只有一個頁面需要緩存控制爲私有。是否有辦法做到這一點?

讚賞任何輸入

回答

1

您不能應用或覆蓋從web.config設置到特定的頁面,但是你可以爲一個文件夾內所有頁面做到這一點,通過下面的設置。

<system.webServer> 
    <httpProtocol> 
    <customHeaders> 
    <remove name="cache-control" /> 
    <add name="cache-control" value="no-cache" /> 
    </customHeaders> 
    </httpProtocol> 
</system.webServer> 

但是,您可以在Page_Load事件的特定頁面的覆蓋cache-control設置。

Response.CacheControl = "Private"; 
0

您也可以通過設置@outputcache指令的位置屬性變化的響應緩存的頁面。

<%@ OutputCache Location="Server" %>