I am trying to display a PDF file in a browser using the action below. When this is executed the result is an entire screen that looks like the image attached. Rendered result It looks like MediaTypeNames.Application.Pdf is being ignored. The same result with Chrome or Firfox. What I am missing?
[HttpGet]
public FileResult ViewFile()
{
Response.AppendHeader("Content-Disposition", "inline; filename=" + Server.UrlEncode("file.pdf") + ";");
var path = @"C:\temp\file.pdf";
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
return new FileStreamResult(stream, MediaTypeNames.Application.Pdf);
}
You can use below below code snippet to display a PDF document in browser.