2013-07-24 48 views
1

我正在ASP.NET MVC(3)應用程序中工作。它是一個訂購系統。當我在「選擇產品」頁面中添加產品時,它將重定向到「查看並應用」頁面以查看購物車。假設我在選擇產品頁面添加產品'A'並移動到審覈並應用並返回到選擇產品頁面並提取產品並添加產品'B'。當我移到Review and Apply頁面時,我只看到產品A.當我通過使用IE的網絡選項卡檢查時,它說服務器響應狀態碼304,因此客戶端使用緩存頁面。在什麼情況下IIS響應304響應代碼

如何解決這個問題,讓服務器發送一個新的頁面,而不是我的304

致謝。

回答

1

將輸出緩存屬性添加到您的控制器或操作。我建議你在你的web.config中使用一個緩存配置文件來實現這一點。

[OutputCache(CacheProfile = "NoCache")] 
public class MyController : Controller 
{ 

} 

這將在您的web.config中system.web元素下。

<caching> 
    <outputCacheSettings> 
    <outputCacheProfiles> 
     <clear /> 
     <add name="NoCache" varyByParam="None" location="ServerAndClient" noStore="true" duration="0" /> 
    </outputCacheProfiles> 
    </outputCacheSettings> 
</caching> 

現在一件事是棘手的是與MVC的新版本(3,4),你會得到一個「出現InvalidOperationException:時長必須爲正數」,如果你對孩子的行動應用緩存配置文件(即如果你使用@ Html.RenderAction)。所以如果你的行爲被這樣調用,你將無法使用它的OutputCache屬性。而是在將會呈現子操作的父操作上使用OutputCache屬性。

實施例:

public class MyController : Controller 
{ 
    [OutputCache(CacheProfile="NoCache")] 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    [ChildActionOnly] 
    public ActionResult ChildAction() 
    { 
     return View(); 
    } 
} 
相關問題