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.
<add name="XHtmlModule" type="CMS.OutputFilter.OutputFilterModule, CMS.OutputFilter" />
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.
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,
return File(data, contentType);
throw new HttpException(404, "File not found");
I did try that actually, but no luck.
I used JustDecompile to see how the OutputFilter worked, and then added the following code to fix the problem:
OutputFilterContext.ApplyOutputFilter = false;
ResponseOutputFilter.UseOutputFilterCache = false;
Have you tried to exclude the URL of your download method from output filter? - This could be done in Settings -> System -> Output filter.
Please, sign in to be able to submit a new answer.