Set custom 404s for ASP and .NET sites


You can set custom 404s for ASP and .NET sites by adding the following code to the bottom of the web.config file before the final </configuration> tag. You must use both options to redirect all 404s.

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="DetailedLocalOnly">
      <error statusCode="404" redirect="404.aspx"/>
    </customErrors>

  </system.web>
</configuration>

The following example shows 404s for all content redirecting to index.html:

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


Was this content helpful?




© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER