I'm developing a Asp.net MVC Core 2.2 web site in IIS. The IIS website that hosts my MVC Core project has been created correctly. My project generates correctly a PDF file. Usually, I just use a jquery function to open that PDF file in browser:
$.ajax({
url: '@Url.Action("CreatePDF", "MyApiController", new { area= "MyArea" })',
dataType: 'json',
contentType: "application/json",
type: 'POST',
cache: false,
data: JSON.stringify(Filtro),
success: function (d) {
if (d.success == true) {
var item = d.data;
var pageurl = '@Url.Content("~/")' + 'Temporal/' + item.PDFName;
window.open(pageurl, '_blank');
}
},
However, I just realized that this MVC Core web site doesn't allow to open any PDF or txt or jpg or whatever file in browser and instead output this message:
localhost page can’t be found
http error 404
My question is:
In a MVC Core web site, how should I open a PDF file in browser from Controller
[Route("[action]")]
[HttpPost]
public ActionResult<BE_Reporte> CreatePDF(BE_Reporte c)
{
BL_Reporte b = new BL_Reporte();
try
{
c = b.CreatePDF(c);
return Ok(new
{
data = c,
success = true,
Message = "PDF created OK"
});
}
catch (Exception ex) { throw ex; }
finally
{
b.Dispose(); b = null;
}
}