Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 918
Goran Obradovic Avatar asked Oct 16 '12 06:10

Goran Obradovic


People also ask

How do I turn off custom errors in IIS?

Click on "Edit Configuration". Click the Custom Errors tab. Select Off for custom error mode.

How do I hide detailed error information for IIS and ASP Net?

To prevent unauthorized users from viewing this privileged information, detailed error pages must not be seen by remote users. This setting can be modified in the errorMode attribute setting for a Web site's error pages. By default, the errorMode attribute is set in the Web.


1 Answers

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]

like image 99
Goran Obradovic Avatar answered Sep 21 '22 12:09

Goran Obradovic