ASP
  Home arrow ASP arrow Trapping HTTP 500.100 - Internal Server Er...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Trapping HTTP 500.100 - Internal Server Error
By: James Shaw
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2003-04-14

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using ASP pages with IIS, you are able to trap the 500.100 error and return a custom made error page to prevent users losing faith in your web site. James will now show you how.

    Using Internet Information Server (IIS), you can trap both compilation and run-time errors that occur in your ASP page.

    Here's an example file that contains errors - we'll run this page in a minute and see how the errors are trapped.

    Test500100.asp

    <%@ Language=JavaScript %>
    <%
       // call a function that doesn't exist...
       Hello ( );
       // or divide by zero
       var a = b / 0;
       // or don't finish a statement
       Unfinished (
    %>

    Any of the errors in this file would cause a HTTP 500.100 error, which in turn would send a generic message back to the browser - probably the infamous "This page cannot be displayed".

    IIS allows you to override this default behaviour, and specify a file that will be called when an error occurs. You can specify an HTML page or an ASP page. I use an ASP page, so the site will send me an email whenever an error occurs. Don't rely on your users telling you that the site crashed!

    The Handle500100.asp File

    The error handling file is just a normal ASP file. What makes it useful is the use of the Server.GetLastError() method to inform both the user and I (via email) what went wrong. We'll look at that code in a minute.

    Just as when an HTTP 404, File not found error occurs, it is a very good idea to apologise profusely and offer your reader some options.

    As you can see, I try to keep the user as happy as possible. The error page looks like any other page on the site, apologises and tries to keep the user from leaving the site in disgust.

    The Server.GetLastError Method

    Microsoft JScript compilation
    Syntax error
    /cya/Test500100.asp, line 11

    The handler wouldn't be very useful if it didn't tell me quickly what was wrong, so I can fix it. An example of the error I get is shown above, with the code to create it shown below:

    (As always, you can get the entire source code by clicking on the icon at the end of the article).

    var oASPError = Server.GetLastError ( );
    var sError = '<p>' + oASPError.Category;
    if ( oASPError.ASPCode > '' )
       sError += ', ' + oASPError.ASPCode;
    sError += '<br><b>' + oASPError.Description + '</b><br>';
    if (oASPError.ASPDescription > '' )
       sError += oASPError.ASPDescription + '<br>';
    if ( oASPError.File != '?' )
    {
       sError += '<b>' + oASPError.File;
       if ( oASPError.Line > 0 )
          sError += ', line ' + oASPError.Line;
       if ( oASPError.Column > 0 )
          sError += ', column ' + oASPError.Column;
       sError += '</b><br>';
    }

    Fairly self-explanatory I hope, and lifted almost verbatim from IIS's default 500 handler. Hey, it's going to work, right?

    Sending the Email

    The last step is to email me the error. The code to do that is shown below, using my trusty SendEmail function that supports CDONTS, ASPEmail, ASPMail and JMail.

    View or download the real source code using the icon at the bottom of this page.

    function Report500100 ( sError )
    {
       // get the page in error
       var sURL = '' + Request.ServerVariables ( "URL" );
       // don't send mail while I'm testing on my dev machine..
       // or if we're running the test file!
       if ( IsDebug ( ) || -1 != sURL.indexOf ( 'Test500' ) )
          return;
       // make up the message body
       var sBody = 'The file "' + sURL + '" generated an Internal Server Error\n\n';
       var dateToday = new Date();
       sBody += 'Time: "' + dateToday.getHours() + ':' + dateToday.getMinutes() + '".\n';
       sBody += sError;
       // send the email
       SendEmail ( '500.100.Handler',
    'BadCode@'
    + sHostDomain, '', 'Reporting error', sBody );
    }

    Note that you're not referred to this page by IIS, so you don't use HTTP_REFERER to find the page in error. Instead, use Request.ServerVariables ( "URL" ). You get the original page name, not Handle500100.asp as you might expect.

    I don't bother sending email when running on my local server, which is what the IsDebug() function detects. I'm the one generating the errors, so there would be little point!

    That's (almost) it. I don't need to describe how to setup IIS to use custom error handling - it's fully described in the IIS help - just browse to your local IISHELP documentation.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Articles
    More By James Shaw

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Accelerating Software Innovation on i on Power Systems

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, for an overview of Rational’s new software offerings and resources to help modernize and accelerate software innovation on i on Power Systems – while ensuring past application investments are protected and continue to grow. Learn how these solutions are helping customers extend their core i5/OS solutions toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    Role of Integrated Requirements Management in Software Delivery

    As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    FREE! Go There Now!


    NEW! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Hello World: Learn how to install and use the Rational Asset Manager Eclipse client

    In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek