IIS 7.5:发送带有自定义错误的http状态代码422

Gor*_*vic 9 error-handling http-status-codes custom-errors iis-7.5

我在asp.net mvc app中使用自定义动作过滤器将http状态代码422和json验证错误列表(基本上是序列化模型状态字典)返回给客户端,我在jQuery中使用全局ajaxError处理程序处理它.

所有这些都适用于开发环境,但我的问题是当自定义错误模式打开(<system.webServer>/<httpErrors errorMode="Custom">)时,IIS用文本替换响应(json)"自定义错误模块无法识别此错误."

如果状态代码为422,我很难正确配置IIS以传递原始响应.任何人都做了类似的事情吗?

Gor*_*vic 12

如果Web服务器配置为传递现有响应,则会将json内容返回给浏览器.

<system.webServer>
  <httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough">
  </httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

MSDN:httpErrors元素[IIS设置架构]