Utility SpotlightWeb Page Error Toolkit

Lance Whitney

Contents

Requirements
Download and Install
Setting Up Your Web Server
Setting Up the Web.config File
Customizing the ErrorPage File
Working in IIS

Most of us who work on the Web, whether as webmaster, IT administrator, or ordinary surfer, are probably familiar with the dreaded 404 error page. This error pops up when the Web page you want can’t be found, and it does so for a variety of reasons, including broken links, a missing page, and a misspelled URL. But 404 errorpages aren't very helpful—they tell you that the page can't be found and list a few possible causes, but they don't point you to the right information (see Figure 1).

fig01.gif

Figure 1 A “not found” error

You undoubtedly get frustrated when you run into one of these errors, and so, of course, do the visitors to your organization's own Web site. As an IT admin, is there anything you can do to make your site more user-friendly when a page cannot be found?

In fact, there is. You can set up a custom error page that replaces the generic 404 page and instead displays useful details for site visitors who bump into trouble. And there is a handy tool that can help you design and implement custom error pages—the free Web Page Error Toolkit from Microsoft.

The Web Page Error Toolkit is an ASP.NET application that taps into IIS. You modify an ASPX Web page and other files included with the Toolkit and then set IIS to deploy your custom page. The error page will display search results so your visitors can more easily find the right information in the event of an error.

By default, the page uses the Microsoft Live Search engine to generate search results (though you can use another search engine if you prefer). The page can also offer alternate spelling suggestions if the URL or search string was mistyped.

Microsoft uses the Web Page Toolkit at its own site to help visitors. Let's say you search for "Microsoft Office" at microsoft.com and mistype it as "Microsoft Ofice". The custom error page displays a message asking if you meant to type "Microsoft Office" and provides a list of search results for the correct term, as shown in Figure 2.

fig02.gif

Figure 2 An error page displaying search results

Requirements

Requirements for the Web Page Error Toolkit include:

  • Windows 2000, Windows Vista, Windows XP, Windows Server 2003, or Windows Server 2008
  • IIS 5.0 or higher
  • ASP.NET 2.0 or higher
  • Visual Studio 2005 or higher

Download and Install

The Web Page Error Toolkit can be downloaded from Live Services. The documentation suggests that you install the downloaded file, WebPageErrorToolkitSetup.msi, to the root of your Web site. However, I recommend you install it to the default directory—c:\program files\Microsoft\Web Page Error Toolkit—and then copy the necessary files and directories to your server's root. This gives you control over which files are stored in the root. After installation, a new folder will appear in the Programs menu called Web Page Error Toolkit with two shortcuts: User Guide and Web Page Error Toolkit Files.

The Toolkit files include:

Web.config.merge This is the file that contains the necessary settings for your web.config file. On an ASP.NET Web site, the web.config file contains certain core settings organized into different sections.

Errorpage.aspx This is the custom error page that will replace the generic 404 error page.

Errorpage.aspx.cs The codebehind page for errorpage.aspx written in C#.

Errorstyle.css The stylesheet for your error page.

UserGuide.docx The documentation in Microsoft Office Word 2007 format.

Readme.rtf This is a brief document that explains what you must do with the web.config.merge file.

MSPL license.rtf A document with the software's licensing information.

You'll also find three subdirectories in the installation directory: App_Code, bin, and Web References.

Setting Up Your Web Server

First, you must copy the necessary files to the root of your Web server if you chose not to install them there. Errorpage.aspx, errorpage.aspx.cs, errorstyle.css, and web.config.merge should be copied to the root. Also copy the three subdirectories: App_Code, bin, and Web References. Be aware when you copy these three subdirectories that they may already exist in your Web server's root. However, you should be safe, as the files in these directories are specific to the Toolkit and unlikely to conflict with any existing files.

Setting Up the Web.config File

Next, you must set up the web.config file. If no web.config file exists in the root of your web server, rename web.config.merge to web.config and use that as your default. But if your Web site runs on ASP.NET, a web.config file should already reside in the root. In that case, you'll want to merge the contents of the web.config.merge file to your existing web.config file.

Before you do this, however, you'll need to change a few of its settings. Open the web.config.merge file in a text editor or in Visual Studio. Look for and modify the parameters for the following sections:

ErrorPage.AppID If you would like to use Live Search as your search engine, you first have to get an ID at the search.live.com Web site. You then enter that ID in this section.

ErrorPage.CultureInfo Here you can enter the culture/locale where you want the search performed. The default value is en-US for US English.

ErrorPage.Domain In this section you enter the name of your domain to tell the Toolkit where to retrieve the search results to display in the error page.

ErrorPage.WebSearchResultsNumber The value you enter here lets you indicate the maximum number of search results to list on the error page. The default is 10; the maximum is 50.

ErrorPage.PerformSpellCheck Here you enter a value of True if you want the error page to display spelling suggestions in the case of mistyped URLs or search strings.

ErrorPage.SpellingMessage In this section you type the syntax of the question you want displayed in the event of a spelling error. The default text string is: Were you looking for {suggestion} instead?

ErrorPage.SearchTitle This is the title of the page that is displayed if subsequent search queries don't deliver the correct content. Otherwise, your site visitors will keep receiving this phrase: "We are sorry, the page you requested cannot be found."

ErrorPage.PrivacyURL, ErrorPage.Site­map.URL, and ErrorPage.CopyrightURL You can add links to these other pages, which are displayed in the footer of your error page.

After you've modified the web.config.merge file, you then must merge its settings to your existing web.config file. The web.config.merge file contains two sections, which are appSettings and system.web. The settings in the appSettings section are unique to the Toolkit, so you can copy and paste those strings directly into the same section in your web.config file. The system.web section contains a single string for customErrors. If the custom­Errors string already exists in your web.config file, comment it out and replace it with the string from the web.config.merge file. Remember to back up your existing web.config file before you make any changes.

Customizing the ErrorPage File

As your next step, you may want to modify the ErrorPage.aspx file. The file is already fully configured, so there's little you need to do here. You may want to change some of the error responses in the page, such as "We are sorry; the page you requested cannot be found" and "See below for results close to your request," to text strings of your own choice. Finally, you can modify the errorstyle.css stylesheet by tweaking the color, font, point size, and similar attributes for your errorpage.aspx file.

Working in IIS

Your final step is to modify the custom error settings in IIS to point to your new custom error page. This process varies depending on which version of IIS you are using.

For IIS 5.0 or IIS 6.0:

  1. Open IIS.
  2. Select the Web site to customize.
  3. Right-click on the site and select Properties from the pop-up menu.
  4. From the Web Site Properties window, click the Custom Errors tab.
  5. Scroll down the list of HTTP errors and select the one you wish to customize—in this case, 404.
  6. Click on the Edit button.
  7. Select URL from the Message type dropdown box.
  8. Type /ErrorPage.aspx in the URL field. Click OK.

For IIS 7:

  1. Open IIS.
  2. Select the Web site you wish to customize.
  3. Double-click on the icon for Custom Error Pages.
  4. Scroll down the list of status codes and double-click on the 404 code.
  5. Select Execute URL from the Path Type dropdown box.
  6. Type /ErrorPage.aspx in the Path Field. Click OK.

You can now test your error page. Open the home page of your own site. In the address field, add a subpage of your site to the URL, but misspell it. Your custom error page should appear with a list of alternate suggestions and potential search results.

You may not be able to completely ensure that visitors will always find what they're looking for on your site, but presenting a custom error page should ease their frustration.

Lance Whitney is an IT consultant, trainer, and technical writer. He has spent countless hours tweaking Windows workstations and servers. Originally a journalist, he took a blind leap into the IT world 15 years ago.