Asp.net web api does not set content length header

I am creating RESTful services using web api. My client is an HTML5 / jQuery application. The service and application work fine on IIS 5.1. But when I switch to IIS 7.5, I see that the response contains the Transfer-Encoding: chunked header, and my client does not understand / display the user interface elements (btw this HTML 5 / jQuery stuff is executed by a third party, and I don’t want to change my code. Why should I? In the end, it worked fine until we switched to IIS 7.5). My questions:

  • How / Where can I add the “Conetent-Length” HTTP header in the web api so that IIS does not “bite” the encode response?
  • Is there a way to disable this site / server level encoding in IIS 7.5?

When I access the service from the browser / fiddler, I get the correct answer (xml / json). I am using Json.net formatting.

+3
source share
2 answers

Use

myHttpResponseMessage.Headers.TransferEncodingChunked = false;

to disable encoded encoding.

+1
source

This may be due to this error, which is fixed after beta:

"DevDiv 388456 - WebHost should not use Transfer-Encoding, marked when the content length is known" http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/06f52b894414#src%2fSystem.Web.Http.WebHost%2fHttpControllerHandler.

Setting response.Headers.TransferEncodingChunked = false; it didn’t help for me.

, , , Fiddler - "" , - .

+1

All Articles