0
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"。

当我创建控制器时,新实例没有被缓存。有人能告诉我如何在这段代码中返回缓存索引吗?

4

1 回答 1

0

您需要重定向到类似的操作

filterContext.Result =  new RedirectToRouteResult(
                    new System.Web.Routing.RouteValueDictionary {
                    { "controller", "Home" },
                    { "action", "IndexCache" });

而不是进行函数调用new HomeController().IndexCache();

于 2013-10-26T05:15:01.483 回答