Most likely it is not a problem in your code but in IE. Contrary to modern browsers, IE does not have a built-in PDF viewer, you need to install it as a plug-in from third parties. For instance, if I recall correctly when you install Acrobat Reader it adds a plugin for IE.
If the plugin is not installed, then IE treats it as an "unknown file type" and just downloads it without displaying.
How to return a file but not attachment in .net web api?
mc
5,511
Reputation points
I am using .net 6 web api and I want to response a pdf file.
I want to display a pdf file in ie11 but it will download directly.
so I google and get a answer that I should set "Content-Disposition" to "inline" not "attchment" but still failed.
how to return a file that ie11 will not open but display it?
[HttpGet]
public IActionResult Get()
{
var file = System.IO.File.ReadAllBytes("1.pdf");
HttpContext.Response.Headers.ContentDisposition = "inline;filename=1.pdf";
return File(file, "application/pdf", "1.pdf");
}
Developer technologies | ASP.NET | ASP.NET Core
4,828 questions
Developer technologies | C#
11,579 questions
1 answer
Sort by: Most helpful
-
Alberto Poblacion 1,571 Reputation points
2022-01-26T07:38:15.537+00:00