Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 263
user396491 Avatar asked Dec 07 '25 10:12

user396491


1 Answers

Use

myHttpResponseMessage.Headers.TransferEncodingChunked = false;

to turn off chunked encoding.

like image 180
Aliostad Avatar answered Dec 08 '25 23:12

Aliostad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!