0

I have this quite strange problem:

When I go to a URL which doesn't exist on my website, it simply shows a white page. The Application_Error event is never run, and the user is not transfered to the 404 page we use.

I need to catch the Application_Error event, to do some logging and also some redirects.

I don't have access to the IIS, as I run my website on a shared webhotel. But with all my other websites this works fine.

Here is my web.config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <pages>
      <controls>
        <add src="~/UC/Filters.ascx" tagName="Filters" tagPrefix="uc2"/>
      </controls>
    </pages>
    <httpRuntime maxRequestLength="1048576" requestValidationMode="2.0"/>
    <customErrors mode="Off" defaultRedirect="ErrorPage.aspx">
      <error statusCode="404" redirect="404-Error.aspx"/>
    </customErrors>
    <sessionState timeout="5000"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="AjaxToolkit" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*"/>
          <conditions>
            <add input="{HTTP_HOST}" pattern="domain.com"/>
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"/>
        </rule>
        <!--To always remove trailing slash from the URL-->
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Any ideas? Thanks :-D

Lars Holdgaard
  • 9,496
  • 26
  • 102
  • 182

1 Answers1

0

Set your custom errors to:

<customErrors mode="RemoteOnly" defaultRedirect="ErrorPage.aspx">
  <error statusCode="404" redirect="404-Error.aspx"/>
</customErrors>
Max
  • 1,543
  • 2
  • 16
  • 31
  • Is this for MVC? take a look at http://stackoverflow.com/questions/6508415/application-error-not-firing-when-customerrors-on/9572858#9572858 – Max May 17 '12 at 10:29