This project is read-only.

MediaTypeFormatter : OnWriteToStream contentHeaders

Topics: Web Api
Jun 6, 2011 at 1:53 PM


I'm currently developing a MediaTypeFormatter to process a pdf report from a report server.

In the OnWriteToStream method there is a property contentHeaders. I tried to add a header like

contentHeaders.Add("content-disposition", new List<string> {"attachment", "filename=result.pdf"});

But in the resulting response i'm not able to find this header. Is this by design or is there something wrong with the code?


Jun 6, 2011 at 7:42 PM

In the current bits the content-disposition header field is not a structured header so you have to provide both the name and the value in string format:

    contentHeaders.Add("content-disposition", "attachment; filename=result.pdf");

It is on our to-do list to provide a better experience.


Jun 9, 2011 at 1:12 PM

I tried to your solution, but it's not providing me any result.

I now consume my service on a separate aspx page, here i write the result to the response and set the additional headers.

Jun 9, 2011 at 2:18 PM

When you say "not providing me any result", do you mean, the content-disposition header is not being returned in the response?

Jun 9, 2011 at 2:47 PM


The content-disposition header is ignored. I don't know if this is relavant information, but I'm returning a stream from sql server reporting services.

Nov 7, 2011 at 10:59 AM


I've tried to do something similar.... wanting the Content-Type to be set to:

application/xml; charset=utf-8

using the following code:

contentHeaders.ContentType = new MediaTypeHeaderValue("application/xml");           

contentHeaders.ContentType.Parameters.Add(new NameValueHeaderValue("charset","utf-8"));

but I only get:

Content-Type: application/xml

in the header of the response.... eventhough contentHeaders.ContentType.ToString() returns "application/xml; charset=utf-8"