Asp.net mvc OutputCache不缓存重定向结果

Asp.net mvc OutputCache不缓存重定向结果,asp.net-mvc,outputcache,response.redirect,Asp.net Mvc,Outputcache,Response.redirect,控制器操作返回重定向结果时,outputcache筛选器似乎不适用 下面是如何重现ASP.Net MVC3默认Internet Web应用程序的问题: 在Web.config中: <system.web> <caching> <outputCache enableOutputCache="true"></outputCache> <outputCacheSettings> <outputCacheProfiles>

控制器操作返回重定向结果时,outputcache筛选器似乎不适用

下面是如何重现ASP.Net MVC3默认Internet Web应用程序的问题:

在Web.config中:

<system.web>
<caching>
<outputCache enableOutputCache="true"></outputCache>
  <outputCacheSettings>
  <outputCacheProfiles>
  <add name="ShortTime" enabled="true" duration="300" noStore="false" />
  </outputCacheProfiles>
  </outputCacheSettings>
  </caching> ...

我在任何地方都找不到指定的此行为。。。这正常吗?如果是这样的话,是否有任何解决办法?

这绝对是预期行为。OutputCacheAttribute仅用于生成ActionResults的字符串。事实上,如果你仔细观察(Reflector/ILSpy是你的朋友),你会特别看到:

string uniqueId = this.GetChildActionUniqueId(filterContext);
string text = this.ChildActionCacheInternal.Get(uniqueId, null) as string;
if (text != null)
{
    filterContext.Result = new ContentResult
    {
        Content = text
    };
    return;
}

我可以理解你的原因,甚至可能导致重定向的“decesion”可能会耗费时间/资源,但似乎你必须自己实现这种“decision caching”。

我希望Http内容被缓存,无论是200还是302状态码。。。谢谢
string uniqueId = this.GetChildActionUniqueId(filterContext);
string text = this.ChildActionCacheInternal.Get(uniqueId, null) as string;
if (text != null)
{
    filterContext.Result = new ContentResult
    {
        Content = text
    };
    return;
}