I created a Action that convert the content of an URL(HTML) into an Image (JPG), and than, return it to me, however, the browser is downloading it instead showing.
The Image is generated dynamically, I don't have it in hard disk.
My code is the following:
[AllowAnonymous]
public FileResult URLToImage(string url)
{
// In some cases you might want to pull completely different URL that is not related to your application.
// You can do that by specifying full URL.
UrlAsImage urlImg = new UrlAsImage(url)
{
FileName = Guid.NewGuid().ToString() + ".jpg",
PageHeight = 630,
PageWidth = 1200
};
return File(urlImg.BuildFile(this.ControllerContext), "image/jpg", urlImg.FileName);
}
What do I need to do to show it in the browser instead downloading it?
Return a FileResult and set the Content-Disposition in the header to Inline
[AllowAnonymous]
public FileResult URLToImage(string url)
{
// In some cases you might want to pull completely different URL that is not related to your application.
// You can do that by specifying full URL.
UrlAsImage urlImg = new UrlAsImage(url)
{
FileName = Guid.NewGuid().ToString() + ".jpg",
PageHeight = 630,
PageWidth = 1200
};
Response.AddHeader("Content-Disposition", "inline; filename="+urlImg.FileName);
return File(urlImg.BuildFile(this.ControllerContext), "image/jpg");
}