【问题标题】:How to catch HTTP Error 400 - Bad Requests and redirect them properly on either asp.net application or in IIS 7.5如何捕获 HTTP 错误 400 - 错误请求并在 asp.net 应用程序或 IIS 7.5 中正确重定向它们
【发布时间】:2011-11-09 13:54:59
【问题描述】:

我如何捕获 http 400 错误错误请求,无论是在 global.asax 文件中还是在 IIS 7.5 中的 asp.net 4.0 代码后面,并使用 301 将它们重定向到某些页面。

错误请求示例:http://www.monstermmorpg.com/Maps-Dark-Passage--------------------------------------------------..

您会看到最后的 2 个“..”是错误的请求。我无法在asp.net代码后面的global.asax或IIS 7.5中正确捕获它

感谢您的任何帮助。

【问题讨论】:

    标签: asp.net iis capture bad-request http-error


    【解决方案1】:

    您是否尝试过通过 web.config?

    <configuration>
          <system.web>
            <customErrors defaultRedirect="Error.htm"
                          mode="RemoteOnly">
              <error statusCode="400"
                     redirect="Redirect.aspx"/>
            </customErrors>
          </system.web>
        </configuration>
    

    Error.htm 将是一个通用的捕获所有错误页面。 400 错误将被发送到 Redirect.aspx,您可以在其中通过代码或 html 进行重定向

    【讨论】:

    • 我无法让它在本地工作,但它确实在服务器上工作。这是一个相关的 Hanselman 帖子:hanselman.com/blog/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多