4

我正在使用 Application_Error 来捕获一些旧版 URL 和 URL 快捷方式。在 Global.vb 我有这个代码:

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Dim serverError = TryCast(Server.GetLastError(), HttpException)
        If serverError IsNot Nothing Then
            Dim errorCode As Integer = serverError.GetHttpCode()
            If 404 = errorCode Then
               ' Do some custom processing here
            End If
        End If
    End Sub

在 web.config 我有这个,以确保所有请求,而不仅仅是以 .aspx 结尾的请求,都由 aspnet_isapi.dll 处理,因此我可以处理它们:

        <add name="ASP.NET-ISAPI-2.0-Wildcard" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv2.0,bitness32" />

在我的开发箱(使用 Cassini)上,这在所有情况下都可以正常工作: /badurl 和 /badurl.aspx 都会导致 Application_Error 触发。

然而,在 IIS7 中,/badurl.aspx 可以按预期工作,但 /badurl 只会导致通用服务器生成的 404 页面。

任何想法是什么导致了差异,以及如何让 IIS7 复制开发服务器的行为?

4

2 回答 2

0

您可以通过两种方式尝试:

  1. 在您的代码中,您可以设置Response.TrySkipIisCustomErrors = true;
  2. 在配置文件中你可以设置:

<customErrors redirectMode="ResponseRewrite mode="On" defaultRedirect="appError.aspx" />

于 2009-10-21T19:10:14.247 回答
0

尝试将此添加到 web.config 文件中。

 <customErrors mode="On" defaultRedirect="appError.aspx">
          <error statusCode="403" redirect="appError.aspx"/>
          <error statusCode="404" redirect="appError.aspx"/>
        </customErrors>
于 2009-10-21T02:25:13.390 回答