error-handlingiis-7.5http-status-codescustom-errors

IIS 7.5: sending http status code 422 with custom errors on


I use custom action filter in asp.net mvc app to return http status code 422 and json list of validation errors (basically serialized model state dictionary) to client, where I handle that with global ajaxError handler in jQuery.

All of this works on development enviroment, but my problem is when custom errors mode is on (<system.webServer>/<httpErrors errorMode="Custom">), IIS replaces response (json) with text "The custom error module does not recognize this error."

I'm having hard time properly configuring IIS to pass-through original response if status code is 422. Anyone did something similar?


Solution

  • If web server is configured to pass through existing response, it will return json contents to browser.

    <system.webServer>
      <httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough">
      </httpErrors>
    </system.webServer>
    

    MSDN: httpErrors Element [IIS Settings Schema]