Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从操作返回缓存的actionresult_C#_Asp.net Mvc_Caching - Fatal编程技术网

C# 如何从操作返回缓存的actionresult

C# 如何从操作返回缓存的actionresult,c#,asp.net-mvc,caching,C#,Asp.net Mvc,Caching,这是行不通的。如果用户未登录,我想返回缓存。这不是最终代码 在为它们提供缓存索引()之前,我需要检查action=“index”和controller=“home” 当我创建控制器时,新实例不会被缓存。 有人能告诉我如何在这段代码中返回缓存索引吗?您需要重定向到如下操作 public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.Controller.Vi

这是行不通的。如果用户未登录,我想返回缓存。这不是最终代码

在为它们提供缓存索引()之前,我需要检查action=“index”和controller=“home”

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

您需要重定向到如下操作

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()
}

而不是进行函数调用
newhomecontroller().IndexCache()

感谢Satpal,但我正在寻找一种不更改url的解决方案
filterContext.Result =  new RedirectToRouteResult(
                    new System.Web.Routing.RouteValueDictionary {
                    { "controller", "Home" },
                    { "action", "IndexCache" });