Sai*_*udo 14 asp.net-mvc actionresult
我有一个简单的控制器返回图像:
public class ImageController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
[OutputCache(CacheProfile = "StationeryImageCache")]
public FileResult Show(int customerId, string imageName)
{
try
{
var path = string.Concat(Config.ImageDir, customerId, @"\", imageName);
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
}
catch(System.IO.FileNotFoundException ex)
{
throw new MissingImageException(imageName);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的经理在代码审查期间发现了FileStreamResult,并提到我应该将其与以下内容交换:
return new FilePathResult(path, "image/jpeg");
Run Code Online (Sandbox Code Playgroud)
这对我来说很有意义,所以我做到了.但是几天之后,我们其他开发人员报告说我返回的一些图像已经损坏了.具体来说,有很多图像在某些时候被切断了.图像的大小是正确的,但底部25% - 40%的图像只是消失了.
在查看文件系统上的原始图像时,它没有任何问题.我在浏览器中填充图像,看起来很好.但是我的控制器只返回了部分图像.更糟糕的是,只有一些图像是问题......大约有30%......虽然我找不到任何有用的图像和有效图像之间的差异.
在尝试调试时,我将操作的结果恢复为FileStreamResult,突然一切都恢复了.
有谁知道对此的解释?
归档时间: |
|
查看次数: |
8205 次 |
最近记录: |