mardi 7 juin 2016

Issues when downloading PDF file from MVC application

I have created a function where a user can download a pdf file from my webpage. The file is stored in a databse and is requested from a webapi. The return value of the webapi is a byte[].

My issue here is that when i run the web application on my local iis this function runs without any errors. I get the pdf file and it is downloaded correctly on my machine. But when i deploy the web application to my Test server this code generates either RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION in chrome with some of the files where as other files are downloaded to the machine but when i try to open the pdf file i get: could not load the pdf file.

This happens with both chrome and IE.

This is my code:

public virtual FileResult DownloadTranslationFile(Guid id)
    Guid assessmentTemplateId = id;
    File translationFile = Services.GetFileContent(assessmentTemplateId);
    var fileName = HttpUtility.UrlPathEncode(translationFile.FileName);
    this.HttpContext.Response.Headers.Add("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    var result = File(translationFile.FileContent.Content, System.Net.Mime.MediaTypeNames.Application.Pdf, fileName);
    return result;

I have been trying to fix this issue for 2 days now but i simply cant figure out what the issue is. Hope you guys can help. Thanks.

Aucun commentaire:

Enregistrer un commentaire