FileContentResult返回为jpg,但IE“将图片另存为"只给png或bmp [英] FileContentResult returned as jpg but IE "Save picture as" only gives png or bmp
问题描述
我有一个MVC 4控制器方法,它返回FileContentResult,如下所示:
I have an MVC 4 controller method returning a FileContentResult as follows:
[OutputCache(CacheProfile = "ImageCache")]
public FileContentResult GetImage(string dl)
{
return File(photoSig.BinaryPhoto, "image/jpeg", "photo.jpg");
}
ImageCache的定义如下:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ImageCache" duration="1" varyByParam="*" location="Server" enabled="true" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
The ImageCache is defined as follows:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ImageCache" duration="1" varyByParam="*" location="Server" enabled="true" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
除IE之外,其他所有功能都正常,当用户将图片另存为...时,它仅向他们提供了另存为PNG或BMP的选项.为什么不以jpg格式显示? Chrome和FF应该提供jpg选项.
Everything works fine except in IE, when the user does a Save picture as..., it only gives them the option to save as PNG or BMP. Why wouldn't it by a jpg? Chrome and FF give the jpg option as it should.
另一个有趣的一点是,它在我的本地机器上运行良好,但在部署时却无法运行...这使我认为这可能是配置问题.但是我不知道从哪里开始寻找. jpg的IIS MIME类型在UI服务器上定义.
Another interesting point is that it works fine on my local box but not when deployed...which makes me think it could be a configuration issue. But I don't know where to start looking. The IIS MIME type for jpg is defined on the UI server.
推荐答案
我认为问题与无存储缓存控制标头有关.请参阅此链接以获取更多信息:
I believe the problem has something to do with the no-store cache-control header. See this link for more information: http://social.technet.microsoft.com/Forums/windows/en-US/e1f5c13b-92f0-4aa7-83b5-344edbe4093d/save-picture-as-jpeg-problem-ie7win-xp-pro-sp3?forum=itproxpsp
我们最终添加了一个IIS重写规则来解决该问题...因此,当它说不存储jpg文件时,我们会将其更改为public或private.然后我可以另存为jpg.
We ended up adding an IIS rewrite rule to solve the problem...so when it says no-store for a jpg file, we change it to something like public or private instead. Then I can save as jpg.
这篇关于FileContentResult返回为jpg,但IE“将图片另存为"只给png或bmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!