Kyle
Kyle

Reputation:

How can I get ASP.NET AJAX to send its JSON repsonse with GZip compression?

I have compression enabled within IIS7 and it works as expected on all responses except for those constructed by ASP.NET AJAX. I have a web service that provides data to the client. When the web service is called directly, it is properly compressed. However, when it is called via ASP.NET AJAX, the JSON response is not compressed.

How can I get ASP.NET AJAX to send its JSON response with GZip compression?

Upvotes: 7

Views: 3046

Answers (3)

bryanbcook
bryanbcook

Reputation: 18393

This should work out of the box. To verify that my ASP.NET AJAX JSON responses use GZip compression:

  1. Download Fiddler (version 2.1.9 is the latest)

  2. Enable Fiddler in IE 7: Tools -> Fiddler2

  3. As all traffic is routed through the proxy, you need to set Fiddler to apply the accept-encoding:Gzip in the HTTP header. Rules -> Apply GZip Encoding

  4. Visit your site through fiddler. If your site is on localhost, IE7 won't route this through fiddler. Fiddler 2.1.8 has a neat feature that maps localhost (127,0.0.1) to http://ipv4.fiddler and http://ipv6.fiddler

  5. Find the asmx request in the Fiddler sessions.

To verify that the request was made with the gzip encoding, look at the Request-Headers in the top panel. You should see "Client: accept-encoding: gzip,deflate"

To verify that the response was sent with gzip encoding, look at the Response-Headers in the bottom panel. You should see "Transport: Content-Encoding: gzip"

I have IIS 7 installed on Vista Business SP1 with no additional configuration, my project is using ASP.NET AJAX with standard web-services.

Hope that helps!

Upvotes: 3

Ray Lu
Ray Lu

Reputation: 26668

Also make sure the JSON request has e.g. accept-encoding:gzip in the HTTP header.

Upvotes: 1

Glenn Slaven
Glenn Slaven

Reputation: 34223

You need to check that the .asmx file extension is on the the list of file types to compress, this is where the ajax json comes from.

Upvotes: 1

Related Questions