I spent the whole of today trying to figure out why IIS on our servers behaved differently from my local IIS and IIS Express when hosting my ASP.NET Web Api.
I have a ValidationActionFilter class which uses Data Annotations. For some reason it wasn’t returning the validation error messages in the response body when hosted on our IIS servers. However, it worked perfectly on both IIS Express and IIS locally.
After a process of elimination we boiled it down to being an issue with the web server itself. A little googling later and we found this post.
So, it turns out that IIS needs a little configuration to allow your HTTP status codes through without it sanitising them!
<configuration> <system.webServer> <httpErrors existingResponse="PassThrough" /> </system.webServer> </configuration>