Hosting ASP.NET Web Api with IIS

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>
Advertisements

One response to “Hosting ASP.NET Web Api with IIS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s