user396491
user396491

Reputation: 941

Asp.net web api not setting content length header

I am building a RESTful services using web api. My client is a HTML5/Jquery application. The service and application works perfectly on IIS 5.1. But when i switch to IIS 7.5, i see the response contains a Transfer-Encoding: chunked header and my client doesn't understand/render UI elements(btw this HTML 5/JQuery stuff is done by a third party and i don't want to change their code. why should i ? after all, it was working fine till we moved to IIS 7.5). My questions are :

  1. How/Where do i add a "Conetent-Length" http header in web api so that IIS doesn't "chunk" encode the response?
  2. Is there a way to disable this encoding at the site/server level in IIS 7.5 ?

When i access the service from browser/fiddler i get the proper response(xml/json). I am using Json.net formatter.

Upvotes: 3

Views: 3829

Answers (2)

LittleColin
LittleColin

Reputation: 81

This could be due to this bug which is fixed post-beta:

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

Setting response.Headers.TransferEncodingChunked = false; didn't work around this issue for me.

Also you are likely to apparently be getting different results in Fiddler due to having "Decode" button pressed at the top which automatically de-chunks the response and removes the transfer-encoding header from the response.

Upvotes: 1

Aliostad
Aliostad

Reputation: 81700

Use

myHttpResponseMessage.Headers.TransferEncodingChunked = false;

to turn off chunked encoding.

Upvotes: 1

Related Questions