我有一个 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/