asp.net-mvc - DonutOutputCache 不适用于图像

标签 asp.net-mvc donut-caching

我有一个 ASP.NET MVC Controller 操作,如下所示:

[HttpGet]
[DonutOutputCache(CacheProfile = "banner")] 
public async Task<ActionResult> Banner(string name, string size = "lg")
{
    // snipped - work out which banner to show today.

    return File(thePathToSomeBannerImageFile, "image/jpeg");
}

配置文件如下所示:

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      ...
      <add name="banner" duration="31536000" varyByParam="*" />
      ...
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

自从添加 DonutOutputCache 后,我用来渲染到浏览器的图像现在将无法加载。我可以在 Fiddler 跟踪中看到一个较大的二进制文件正在访问浏览器,但我似乎无法渲染它。

删除 DonutOutputCache 会使图像再次出现。

我尝试过清除缓存等。有什么想法吗?

最佳答案

啊,刚刚从这个链接中弄清楚:Doesn't work w/ Files? .

基本上,DonutOutputCache 使用 ContentResult在内部仅适用于基于文本的内容。因为我在 FileResult 中返回二进制响应它把事情搞乱了。幸运的是,它与内置的 OutputCache 并行工作,因此我可以按如下方式修改我的操作,并且它按预期工作。我实际上只需要 DonutOutputCache 来处理我网站中基于文本的其他部分。我试图只用一个缓存属性来统治它们,但结果却被自己绊倒了。

[HttpGet]
[OutputCache(CacheProfile = "banner")] 
public async Task<ActionResult> Banner(string name, string size = "lg")
{

}

关于asp.net-mvc - DonutOutputCache 不适用于图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27600773/

相关文章:

asp.net-mvc - ASP.NET MVC 5 中的路由

c# - 用于 IEnumerable ViewModel 的 Razor Html.DisplayNameForInnerType

c# - Mvc Donut Caching 以编程方式禁用缓存

asp.net - 在 ASP.NET MVC 中使用不可缓存的表单进行缓存

asp.net - 如何测量 Live ASP.NET MVC Web 应用程序的内存使用情况?

html - 从 MVC 中生成的 HTML 中删除多余的空格

asp.net-mvc - N服务总线 : No destination specified for message(s):

caching - ASP.NET MVC 3 中是否提供 donut 缓存

asp.net - 从输出缓存中排除动态渲染的用户控制