Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

To customize 404 handling and based on the hosting company's suggestion, we are currently using the following web.config setup. However, we quickly realized that with this configuration, any page error (500 error) are also getting redirected to this custom error page. How can I modify this config file so we can continue to handle 404 with custom file while still able to view on-page error?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/Custom404.html" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Custom404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/Custom404.html" />
</customErrors>
</system.web>
</configuration>
share|improve this question
    
Clarification, the script is actually classic asp and the server is II7. The goal is to redirect 404 results to a custom page while still being able to see error message if a page runs into 500-type of errors (instead of redirecting to a custom 500 error page). At current setup, 404 and 500 errors will always reach /custom404.html. –  Mark Sep 23 '09 at 18:58
add comment

4 Answers

Try this -

<configuration>
   <system.webServer>
      <httpErrors errorMode="Custom" defaultResponseMode="File" >
         <remove statusCode="404" />
         <remove statusCode="500" />
         <error statusCode="404" 
            path="404.html" />
         <error statusCode="500" 
            path="500.html" />
       </httpErrors>
   </system.webServer>
</configuration>

The 404 error page is 404.html and it is located in my root, likewise the 500 page

share|improve this answer
add comment

Just add another value for 500 errors.

<customErrors mode="On">
<error statusCode="404" redirect="/Custom404.html" />
<error statusCode="500" redirect="/Custom500.html" />
</customErrors>
share|improve this answer
    
Thank you for the answer, but this did not work for me. A page with 500 error still redirects to /custom404.html after including your suggestion. I've added some additional note below the original question, hopefully clarifies my goal a bit. –  Mark Sep 23 '09 at 19:00
add comment

I am discovering a lot of complicated work-arounds for Classic ASP in IIS 7.5 for dealing with IIS 6 type of custom error handling for a specific error code, typically 404. I hope this helps people who stumble upon it.

I am running IIS 7.5 R2 but I think this applies to IIS 7 in general.

If your web.config file has this in it:

<customErrors mode="On">

...inside the IIS Manager you probably selected Edit Features under Error Pages to change the features on the Edit Error Pages Settings panel. If you change this to Custom Error Pages (customErrors mode="On"), you are forced to setup handling of each and every error number. So don't do that.

All you have to do is RIGHT click on the error number you wish to handle and select Edit. There you can point to a custom error page you create or redirect to a URL. Rather than create a custom error page that you have to remember to update when your site design or menus change, I always suggest redirecting to the home page and add something to the querystring like ?syserror which you can then handle from the home page. My technique is to check for this in the home page scripting and popup a friendly message letting them know their page was not found and they were directed to the home page.

Your web.config file would look something like this:

<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" 
path="http://yoursite.com/index.asp?syserror" responseMode="Redirect" />
</httpErrors>

I also suggest that you do not enable detailed error messages on a production Website as a security precaution, even for local. Just look up the details in your system log.

Just my 2 cents, hope it helps and please let me know if you think I am incorrect on anything here.

share|improve this answer
add comment

Classic ASP doesn't pass through the error in IIS7 by default. To enable that for a site, run the following from the command line, being sure to replace {sitename} with your name site:

c:\windows\system32\inetsrv\appcmd.exe set config "{sitename}" -section:system.webServer/httpErrors /existingResponse:"PassThrough" /commit:apphost

Additionally, make sure to turn off IIS friendly errors. They really aren't friendly.

share|improve this answer
add comment

protected by Tom O'Connor Jun 26 '13 at 7:05

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?