How to setup custom 404′s for IIS and ASP.net through web.config
If you use Rackspace’s cloudsites, you’ll find that not having direct access to IIS makes you learn how to use Web.config for everything! Today we had to put up a custom 404 page, which we got to work at first for any missing .aspx page, but didn’t work for a random missing directory. After a few minutes of searching, I found my answer here. Hope you find it useful:
Classic ASP and Static Content:
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/404.asp" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
.NET
<configuration>
<system.web>
<customErrors defaultRedirect="404.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
</system.web>
</configuration>
This exampled shows 404′s for all content redirecting to index.html, you will want to include both to get all pages (.aspx and everything else) to redirect correctly:
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/index.html" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/index.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/index.html" />
</customErrors>
</system.web>
</configuration>