4

I'm using Application_Error to catch some legacy URLs and URL shortcuts. In Global.vb I have this code:

    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

In web.config I have this, to ensure that all requests, not just ones ending in .aspx, are handled by aspnet_isapi.dll so I get to process them:

        <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" />

On my development box (using Cassini), this works fine in all cases: Both /badurl and /badurl.aspx cause Application_Error to fire.

In IIS7, however, /badurl.aspx works as expected, but /badurl just results in a generic server-generated 404 page.

Any ideas what causes the difference, and how I can get IIS7 to replicate the development server's behavior?

Herb Caudill
  • 50,043
  • 39
  • 124
  • 173

2 Answers2

0

try to add this to web.config file.

 <customErrors mode="On" defaultRedirect="appError.aspx">
          <error statusCode="403" redirect="appError.aspx"/>
          <error statusCode="404" redirect="appError.aspx"/>
        </customErrors>
Henry Gao
  • 4,858
  • 1
  • 21
  • 21
0

You can try in two ways:

  1. in your code you can set Response.TrySkipIisCustomErrors = true;
  2. in config file you can set:

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

Enes
  • 3,951
  • 3
  • 25
  • 23
  • Where would 'Response.TrySkipIisCustomErrors = true' go? The problem is that my code isn't getting hit at all, as far as I can tell. (I already have the '' entry in web.config). – Herb Caudill Oct 22 '09 at 13:50
  • @Herb 'Response.TrySkipIisCustomErrors = true' would go in the body of you method. Let's say imediatelly after Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs), as far as concerns check if your entry have this attribute redirectMode="ResponseRewrite". You must not have both. It is one or the other. I would reccomend the second one. – Enes Oct 22 '09 at 17:21