C# 如何从操作返回缓存的actionresult
这是行不通的。如果用户未登录,我想返回缓存。这不是最终代码 在为它们提供缓存索引()之前,我需要检查action=“index”和controller=“home” 当我创建控制器时,新实例不会被缓存。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
有人能告诉我如何在这段代码中返回缓存索引吗?您需要重定向到如下操作
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" });