[英]How to return cached actionresult from an action
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.Controller.ViewData["currentuser"] == null)
{
filterContext.Result = new HomeController().IndexCache();
}
base.OnActionExecuting(filterContext);
}
[OutputCache(Duration=3600)]
public ActionResult IndexCache()
{
return view()
}
這是行不通的。 如果用戶未登錄,我想返回緩存。 這不是最終代碼。
在為它們緩存Index()之前,我需要檢查action =“ index”和controller =“ home”。
當我創建控制器的新實例不被緩存。 有人可以告訴我如何在此代碼中返回緩存的索引嗎?
您需要重定向到類似
filterContext.Result = new RedirectToRouteResult(
new System.Web.Routing.RouteValueDictionary {
{ "controller", "Home" },
{ "action", "IndexCache" });
而不是使函數調用new HomeController().IndexCache();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.