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

3

12

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?

Vallievalliere answered 16/10, 2012 at 6:31 Comment(1)
Had the same issue when returning HTTP 402 Payment Required.Kenyon
V
20

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]

Vallievalliere answered 16/10, 2012 at 11:30 Comment(0)
L
0

enter image description here

Make the following settings for IIS 7.5, this works fine for me, the most important thing here was the installation of the existingResponse="Replace":

<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace" detailedMoreInformationLink="http://YouLink" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
            <error statusCode="401" prefixLanguageFilePath="" path="C:\path\to\401.htm" responseMode="File" />
            <error statusCode="403" prefixLanguageFilePath="" path="C:\path\to\403.htm" responseMode="File" />
            <error statusCode="404" prefixLanguageFilePath="" path="C:\path\to\404.htm" responseMode="File" />
            <error statusCode="405" prefixLanguageFilePath="" path="C:\path\to\405.htm" responseMode="File" />
            <error statusCode="406" prefixLanguageFilePath="" path="C:\path\to\406.htm" responseMode="File" />
            <error statusCode="412" prefixLanguageFilePath="" path="C:\path\to\412.htm" responseMode="File" />
            <error statusCode="500" prefixLanguageFilePath="" path="C:\path\to\500.htm" responseMode="File" />
            <error statusCode="501" prefixLanguageFilePath="" path="C:\path\to\501.htm" responseMode="File" />
            <error statusCode="502" prefixLanguageFilePath="" path="C:\path\to\502.htm" responseMode="File" />
            <error statusCode="400" prefixLanguageFilePath="" path="C:\path\to\400.htm" responseMode="File" />
</httpErrors>
Lollipop answered 24/2, 2019 at 13:44 Comment(0)
R
0

Check if error pages are configured for your application in IIS. You need to add your custom error page for the status code eg: 429

IIS Error pages configuration

Add the status code HTMLstrong text page. It should resolve the issue

Error HTML page configuration

Reba answered 2/3, 2021 at 9:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.