【问题标题】:IIS 7.5: sending http status code 422 with custom errors onIIS 7.5:发送带有自定义错误的 http 状态代码 422
【发布时间】:2012-10-06 04:51:44
【问题描述】:

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

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

如果状态码为 422,我很难正确配置 IIS 以传递原始响应。有人做过类似的事情吗?

【问题讨论】:

  • 返回 HTTP 402 Payment Required 时遇到了同样的问题。

标签: error-handling iis-7.5 http-status-codes custom-errors


【解决方案1】:

检查是否在 IIS 中为您的应用程序配置了错误页面。您需要为状态代码添加自定义错误页面,例如:429

添加状态码 HTMLstrong 文本页面。它应该可以解决问题

【讨论】:

    【解决方案2】:

    为 IIS 7.5 进行以下设置,这对我来说很好,这里最重要的是安装 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>
    

    【讨论】:

      【解决方案3】:

      如果Web服务器配置为通过现有响应,它将json内容返回给浏览器。

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

      MSDN: httpErrors Element [IIS Settings Schema]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-14
        相关资源
        最近更新 更多