.NET MVC,浏览器端访问图片链接直接下载而不是查看

 如果将ContentType设置为application/octet-stream,那么在浏览器中会自动下载,需要将ContentType设置为对应类型

还有一种是设置了错误的参数,去掉文件名即可

public ActionResult Image()
{
string filePath = "D:\\123.png";
//return File(CommonHelper.GetImage(filePath), "image/png","123.png");//这种写法是错误的
return File(CommonHelper.GetImage(filePath), "image/png");
}

posted @ 2023-09-19 15:12  奇迹之耀  阅读(51)  评论(0编辑  收藏  举报