Skip to main content
Visual C++ Samples 

Demonstrates techniques for generating error responses to send to the user. Shows the use of ATL Server's default error response, custom static responses, and custom dynamic responses.

Use a browser to view ShowErrors.srf and use the form to choose the error that the server will send back when you click Submit. Select an HTTP status code using the drop-down list and optionally type a numeric subcode into the text box. To view the response generated by the default error provider, leave the Return Custom Error box unchecked. To view a custom error response, select that box. If you select 404 with a subcode of zero, you should see the custom error file (404.htm) that was deployed to the local errors folder.

To ensure that you are seeing the errors sent by the server, you must disable Internet Explorer friendly error messages. On the Tools menu, click Internet Options and select the Advanced tab. Under the Browsing heading, make sure that the Show friendly HTTP error messages is not selected. Note that the dynamically generated custom errors look similar to Internet Explorer friendly error messages but can be viewed in any browser because they are generated by the server.

If Return Custom Error is cleared, the request handler builds an error code from the selected HTTP status code and subcode using the HTTP_ERROR macro. This value is returned from ValidateAndExchange and the ATL Server infrastructure uses CDefaultErrorProvider to build a response.

If Return Custom Error is selected, the request handler does the following:

  1. Clears the response object of any headers and body that may have been set.

  2. Prevents the error response from being cached by setting the Cache-Control and Expires response headers.

  3. Applies the HTTP status code to the response object.

  4. Tries to transmit a file that corresponds to the selected status code and subcode from the local errors folder.

  5. If the previous step fails, tries to transmit a file from the errors folder for the site.

  6. If the previous step fails, generates a generic response that features instructions for the user to try to work around the problem as well as technical details (time, date, URL, status code, and subcode) that can be used by technical support to track down the cause of the problem.