I have been trying to have my web app to redirect to a custom 404 page. It works for all urls except if they have a ".aspx" extension
The server is a Windows Server 2008 and here are the following settings I have in my web.config (using google.com as a quick example):
<customErrors defaultRedirect="http://www.google.com" mode="On" redirectMode="ResponseRedirect"></customErrors>
<httpErrors errorMode="Custom">
<clear />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404-Page/" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/404-Page/" responseMode="ExecuteURL" />
</httpErrors>
Again the HTTP Errors work for everything but extensions of ".aspx"
Well to solve this issue, we ended up having to create a module that hijacks any errors and transfers the user to my custom 404 page that is set in the web.config (under customErrors
). The module would add an event handler to whenever the application gets an error:
public void Init(HttpApplication context)
{
context.Error += new EventHandler(FileNotFound_Error);
}
And the function FileNoteFound_Error
does the redirection.