有沒有一種方法可以防止在對某個操作設置OutputCache屬性時緩存頁面?防止在發生錯誤時緩存返回的視圖
這樣,當頁面隨後被打中時,它不會存儲先前返回的通用錯誤頁面。
下面的示例顯示了一個實例,在該實例中,應用程序不會緩存該頁面,並且會因爲任何原因(db timeout等)導致異常。
[OutputCache(CacheProfile = "Homepage")]
public ActionResult Index()
{
var model = new HomepageModel();
try
{
model = Db.GetHomepage();
}
catch
{
//Do not want to cache this!
return View("Error");
}
//Want to cache this!
return View();
}
更新 最後,我只是需要增加以下內容:
filterContext.HttpContext.Response.RemoveOutputCacheItem(filterContext.HttpContext.Request.Url.PathAndQuery);
這是從another question拍攝。
Hi @Clicktricity。感謝您的答覆。不幸的是重定向用戶是不可能的。我一直在尋找另一個類似的問題 - http://stackoverflow.com/questions/1043112發現'RemoveOutputCacheItem'後。這或多或少是我想要的。 – 2010-09-15 10:27:38