0

我想運行一個調用應用程序,在所有輸出緩存頁面上調用網站,以便爲用戶緩存所有緩存的分頁。使用瀏覽器時,頁面緩存正確,但我希望能夠運行緩存用戶所有頁面的功能。outputcache控制檯應用程序的網站

即時通訊使用new System.Net.WebClient().DownloadString("http://url");但使用此調用時頁面不會緩存。

Cacheing屬性

[ChildActionOutputCache(("CacheAll"), Location = OutputCacheLocation.Server)] 

屬性功能

public class ChildActionOutputCacheAttribute : OutputCacheAttribute 
    { 
     public ChildActionOutputCacheAttribute(string cacheProfile) 
     { 
      var settings = (OutputCacheSettingsSection)WebConfigurationManager.GetSection("system.web/caching/outputCacheSettings"); 
      var profile = settings.OutputCacheProfiles[cacheProfile]; 
      Duration = profile.Duration; 
      VaryByParam = profile.VaryByParam; 
      VaryByCustom = profile.VaryByCustom; 
     } 
    } 

的web.config的特性屬性

<caching> 
     <outputCacheSettings> 
     <outputCacheProfiles> 
      <add name="CacheAll" 
       duration="43200" 
       location="Server" 
       varyByParam="*"/> 
     </outputCacheProfiles> 
     </outputCacheSettings> 
    </caching> 
+1

你正在使用什麼樣的緩存? – SLaks 2013-02-28 15:22:27

+0

使用costum生成的outputcache屬性標記控制器方法。 – user473104 2013-02-28 15:23:58

回答

0

我知道這是一個老問題,但對於其他人使用Google爲什麼輸出緩存不適用於他們的控制檯應用程序提出的請求 - 答案是 餅乾。

您所做的請求沒有cookie,服務器的響應具有新的cookie - 因此它不緩存輸出。

使用代碼在這個答案讓你的請求,一切都會OK緩存:https://stackoverflow.com/a/3892075

我所要做的就是讓我的應用程序的主頁的請求。這會話會話排序,會話cookie返回。這些cookie隨後被添加到後續請求中(我想要緩存的頁面),並且所有內容都按預期工作。

相關問題