Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


October 2001

Forcing IIS to Display Custom Error Messages

RSS
Subscribe to Windows Web Solutions | See More Windows NT 4.0 Service Pack 6 (SP6) Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

I'm running IIS 4.0 on Windows NT 4.0 Service Pack 6a (SP6a). I've created a Web site that uses host headers, and I've designed custom error messages for the site. I understand that the custom 404 error messages should appear every time a user requests in the URL a file or directory that doesn't exist on the Web site. However, here's what happens. If the URL refers to a

  • nonexistent folder, such as http:// mydomain/nofolder, the custom error page appears
  • nonexistent file ending in .htm, such as http://mydomain/nofile.htm, error 404 Object not found appears
  • nonexistent file ending in .html, such as http://mydomain/nofile.html, error 404 Object not found appears
  • nonexistent file ending in a custom extension, such as http://mydomain/ nofile.zzz, error 404 Object not found appears

How can I get my custom error page always to appear?

IS handles error processing in a couple of different ways. Usually, when you request a file, folder, or virtual directory that doesn't exist, IIS looks up the target's error 404 Object not found to see whether you've set up custom processing. If you've set up a custom page, IIS presents that page. If you haven't, IIS presents the default message. The exception to this rule is when you call an extension for which you used Application Mappings to map to a .dll or .exe file that processes that extension. For example, Active Server Pages (.asp) files are mapped to asp.dll, and server-side include (.ssi) files are mapped to ssiinc.dll.

In these and other cases in which the file extension is mapped to an application-processing executable file, IIS simply hands off the error-processing task to the application. Consequently, you must code error-handling logic into the application.

In your situation, the nonexistent folder presented the custom message, which tells you that the custom message works when it's called. So the question is, why isn't the custom message called in all other cases? This problem can occur when you've mapped .htm or .html files to asp.dll or ssiinc.dll so that you can put script in standard .html files and IIS can process them. Because IIS is supposed to launch a scripting engine that then attempts to process a nonexistent file, IIS returns error message 404 object not found instead of a standard HTML error, bypassing your custom error message. This behavior is true for your custom file mapping as well.

You can, however, force IIS to check whether a file exists before IIS hands the file off to the application mappings. To force IIS to check, follow these steps:

  1. Right-click a Web site, folder, or virtual directory, then select Properties.
  2. Click the Home Directory tab (for a Web site), the Directory tab (for a folder), or the Virtual Directory tab (for a virtual directory).
  3. Click Configuration.
  4. Select an application mapping from the list, which Figure 1 shows.
  5. Click Edit.
  6. In the Add/Edit Application Extension Mapping dialog box, which Figure 2 shows, select the Check that file exists check box.

When you've selected the Check that file exists check box, IIS checks to make sure that the file (in this case, an .shtml file) exists and that the user has proper permissions to it before IIS passes the file to ssiinc.dll. If the requested file doesn't exist, the usual error processing occurs; if you've created a custom error message, that custom error message will appear.

By default, this feature is disabled, largely for performance reasons. When you enable the feature, IIS opens the file, then hands the file off to the application-mapped executable file, which then also opens the file. The performance penalty for opening each file twice might or might not be acceptable depending on your server's load and capabilities.

However, you receive a security benefit from enabling the Check that file exists feature. If an intruder attempts to send your server an improperly formatted request that invokes a mapped extension, IIS won't pass the improperly formatted request to the called .dll or .exe file because IIS checks to see whether a file exists before application processing begins. In fact, in the article "Improperly Formatted HTTP Request May Cause INETINFO Process to Fail" (http:// support.microsoft.com/support/kb/articles/q234/9/05.asp), Microsoft recommends enabling this feature to prevent such problems. For more information about custom error messages, see the Microsoft articles "PRB: IIS Fails to Display Custom Error Messages for .asp Files" (http://support .microsoft.com/support/kb/articles/q176/ 9/19.asp) and "Configuring Custom Error Messages in IIS 5.0" (http://www.microsoft.com/technet/iis/custerr.asp).

End of Article



Reader Comments
Using the above method, if the filename.html is not correct, it will work. But if the folder name in the URL is not correct it is showing the Default error message "404 Object Not Found"

Anonymous User November 26, 2004 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

More fun TechEd 2005 Resources

Kevin points out some more TechEd resources ...

What service packs and fixes are available?

...


IIS and Web Administration Whitepapers The Five Secrets to Controlling Your SharePoint Environment

Extended Validation SSL Certificates

Related Events Check out our list of Free Email Newsletters!

IIS and Web Administration eBooks Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Related IIS and Web Administration Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Microsoft Exchange & Windows Connections event returns to Las Vegas Nov 10 - 13
Connections returns to Las Vegas for this exciting event where each attendee will receive SQL Server 2008 standard with 1 CAL. Co-located with Microsoft ASP.NET, SQL Server, and SharePoint Connections with over 250 in-depth sessions.

Free Online Event! Virtualization:Get the Facts!
Register now and attend this free, live in-depth online conference on November 13 and 20, 2008, produced by Windows IT Pro. All registrants are eligible to receive a complimentary one-year digital subscription to Windows IT Pro (a $49.95 value)!

Check Out Hyper-V Video on ITTV
Watch Karen Forster's interview on Hyper-V's performance on ITTV.net.

Ease Your Scripting Pains with the Flexibility of PowerShell!
Join MVP Paul Robichaux on December 11, 2008 at 11:00 AM EDT as he equips you with PowerShell basics in 3 introductory lessons, each followed by a live Q&A session—all on your own computer!

PASS Community Summit 2008 in Seattle on Nov 18-21
The don’t-miss event for Microsoft SQL Server Professionals. Register now and you’ll enjoy top-notch Microsoft and Community speakers and more.



Speed Up Your PC!
Try Diskeeper 2008 with InvisiTasking Free Now!

Get Protected -- Data Protection Manager 2007
Protect your virtualized environment with Data Protection Manager

Agent-less Remote Backup Service, Free 30 Day Trial
Award winning remote backup service at a competitive price with no min GB/month. Sign up Now!

ScriptLogic Cartoon Caption Contest
Submit your caption and you will be entered to win $198.42

List Your Products in Our Technology Resource Directory
Don't miss the chance to post your free listing in this comprehensive directory for IT and developer professionals, powered by Windows IT Pro. But hurry! Deadline ends Oct. 9.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing