Tuesday, March 31, 2015

HttpResponseMessage PDF file is downloading as HTML using StreamContent

If you have a PDF file which is accessed using StreamContent on HttpResponseMessage it is important to set MediaTypeHeaderValue to the correct value for PDF documents. Otherwise the browser will assume it is HTML begin accessed. This can be set with the following line of code:
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

No comments:

Post a Comment