iactionresult 图片_asp.net core PhysicalFileResult导致浏览器地址栏访问图片变成了下载...

[HttpGet("DownloadFile")]

public IActionResult DownloadFile([FromServices]IHostingEnvironment env, string id)

{

Attachment attachment = AttachmentSystem.GetById(User.Corp.Id, id);

if (attachment == null)

{

return NotFound();

}

string path = Path.Combine(env.ContentRootPath, attachment.SavePath);

if (!System.IO.File.Exists(path))

{

return NotFound();

}

return PhysicalFile(path, MimeMapping.GetMimeMapping(Path.GetExtension(path)), attachment.SourceName + Path.GetExtension(path));

}

用以上方式输出图片,地址栏直接访问会下载图片,怎么修改才能直接在浏览器里显示


版权声明:本文为weixin_39958112原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。