ASP.NET MVC3:通过控制器加载图像
我尝试使用此处的答案,但它不起作用。我有以下代码:
public ActionResult ShowImage()
{
using (FileStream stream = new FileStream(Path.Combine(Server.MapPath("/App_Data/UserUpload/asd.png")), FileMode.Open))
{
FileStreamResult result = new FileStreamResult(stream, "image/png");
result.FileDownloadName = "asd.png";
return result;
}
}
当我打开页面时,出现错误:“无法访问已关闭的文件。”。我对这个错误进行了一些谷歌搜索,但我只发现这个错误与上传相关。这里出现问题的原因是什么?
I tried using the answer from here, but it did not work. I have the following code:
public ActionResult ShowImage()
{
using (FileStream stream = new FileStream(Path.Combine(Server.MapPath("/App_Data/UserUpload/asd.png")), FileMode.Open))
{
FileStreamResult result = new FileStreamResult(stream, "image/png");
result.FileDownloadName = "asd.png";
return result;
}
}
When I open up the page I get an error which says: "Cannot access a closed file.". I did some googling on the error, but I only found this error associated with uploading. What causes the issue here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样:
或者如果您想要一个单独的文件名:
Try like this:
or if you want a separate filename: