The development web server fires Application_Error on 404, why is IIS7 not working?

I use Application_Error to catch some legacy URLs and link 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 those that end in .aspx, are handled by aspnet_isapi.dll, so I can handle 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" /> 

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

In IIS7, however, /badurl.aspx works as expected, but / badurl simply leads to a generated server 404 page.

Any ideas what makes the difference, and how can I get IIS7 to replicate the behavior of the development server?

+4
source share
2 answers

try adding this to the web.config file.

  <customErrors mode="On" defaultRedirect="appError.aspx"> <error statusCode="403" redirect="appError.aspx"/> <error statusCode="404" redirect="appError.aspx"/> </customErrors> 
0
source

You can try in two ways:

  • in your code you can set Response.TrySkipIisCustomErrors = true;
  • in the configuration file that you can install:

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

0
source

All Articles