If you don't have the XML snippet below in your Web.config
and your .NET app tries to return a 400 with custom data, you get this:
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 19 Apr 2011 17:47:46 GMT
Content-Length: 11
Bad Request
NOTE You only get this if you're making requests from a REMOTE IP! If you're testing from localhost, you won't see this. You'll see the custom response you want. Don't be fooled! Test your service from a remote machine!
Ok, so ... with this stuff in your Web.config, you'll get what you want:
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 19 Apr 2011 17:49:02 GMT
Content-Length: 25
{"my":["custom", "json"]}
This was exactly what I was looking for. Thanks.
For those like me who need to understand why this works, I did the research. By default IIS will mask your error codes and replace them with default errors. The "PassThrough" option tells IIS to leave your custom errors alone and render them as-is.