I have a Kentico installation with a custom MVC controller that downloads a file. I have attached the code below.
I have verified (by putting this code into a different MVC project) that it works fine. However, in Kentico, the document is unreadable and even file sizes are different.
After a couple of hours I managed to determine that commenting out the OutputFilter in the web.config resolved my problem.
The question I have is - is there a way to deactivate the output filter for an MVC controller in some way? Obviously removing it entirely is not the appropriate solution.
[HttpGet, Authorize]
public FileContentResult Download(string id)
{
var path = @"C:\Windows\TEMP\file.pdf";
if (path != null && System.IO.File.Exists(path))
{
string name = Path.GetFileName(path);
byte[] data = System.IO.File.ReadAllBytes(path);
string contentType = MimeMapping.GetMimeMapping(path);
var cd = new ContentDisposition
{
FileName = name,
Inline = true,
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(data, contentType);
}
throw new HttpException(404, "File not found");
}
↧