Home arrow ASP arrow Page 6 - Replacing the Error 500 ASP Page

Replacing the Error 500 ASP Page

This article looks at how error information is stored and obtained in ASP 3.0 - the ASPError object, this information is then used in the creation of a new, better error page.

Author Info:
By: Wrox Team
Rating: 5 stars5 stars5 stars5 stars5 stars / 91
January 20, 2003
  1. · Replacing the Error 500 ASP Page
  2. · The ASPError Object
  3. · Editing the ASP Error Page
  4. · Extending the Functionality
  5. · E-Mailing Errors
  6. · SourceSafe Integration
  7. · Conclusion

print this article

Replacing the Error 500 ASP Page - SourceSafe Integration
(Page 6 of 7 )

One of the more interesting aspects of adding a text editor to the web page itself is the way in which source-control fits in to the equation. At first glance, it would seem that editing in this manner would break many guidelines and best practices on source-control.

When examined in more detail, it is actually quite an appealing option. Although Source Safe is used as an example below, a source-control provider could potentially be used.

Firstly, as a file can be checked out, edited, and checked back in in quick succession, there is less likelihood of preventing other users from editing a file than is normally the case. Secondly, changes are often made to code to test it without actually checking the file out of SourceSafe.

When this is the case, there is potential for any changes made to be lost if the source-controlled version is checked out over the top of this file. The final, and possibly the biggest benefit is the ability to add comments to the file.

Whenever a change is made, the error message that the user is trying to correct, along with which machine the error was on, the server configuration, and so on, could all be stored as comments, providing in-depth auditing of bug-fixes to a system.

To achieve this functionality, there are two possibilities - either using the command-line SourceSafe tools, or using the SourceSafe object-model.

In the included source-code, the object model has been used for three reasons. Firstly, it is simply a COM object like any other, itís designed just for automating tasks such as this, and provides greater functionality than the command-line version.

Secondly, running executables on unattended servers is never a wise thing to do as feedback via a UI may be required at some point, locking processes on the server until interaction is given. Finally, the IIS user must be given permissions to invoke executables if the command-line option is to be used.

This would create a potential security risk, giving more permissions than are strictly necessary to a guest user account.

Performing operations using the SourceSafe object-model requires only a couple of method calls. The code below gives an example of how to check out a file using this method:

Set objSS = Server.CreateObject("SourceSafeTypeLib.VSSDatabase")
objSS.VSSItem("c:\sslocal\test.txt").Checkout "", "", VSSFLAG_USERROYES

As can be seen from this code, in addition to knowing what file the action is to be performed on, there are four pieces of information that are required:

VSSFLAG_USERROYESThis is constant informing SourceSafe that the ReadOnly flag on the file should be utilized
INI_PATHThis is the path to the srcsafe.ini file that contains the configuration data for the SourceSafe database
USERNAMEThis specifies the username that all actions should be carried out under
PASSWORDThis parameter contains the password for the specified username.

Using these values, and other methods, such as CheckIn and UndoCheckout, all of the necessary functions can be carried out on the file being edited. Unfortunately, some users may have problems instancing this object, with an error being raised of "Invalid Class String".

This error is generally due to permission problems with the anonymous user. If this is the case, then Read/Execute NTFS rights should be given to the user on the SSAPI.DLL file located in the folder "...\Program Files\Microsoft Visual Studio\Common\VSS\win32". Further information on this error can be found at the referenced URL given at the bottom of this article.

Alternatively, a couple of lines of text such as the following could be used to invoke the command-line version:

strCommand = "c:\...\Win32\ss.exe Checkout """ & strFileName & """ -GWR"
Set objShell = Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True

The ellipsis ("...") should be replaced with the path to SourceSafe's folder (usually "C:\Program Files\Microsoft Visual Studio\Common\VSS"), and the "Checkout" sub-string can be replaced with other command such as "Checkin" and "UndoRollback". For the command-line version to function correctly, several environment variables such as SSUSER and SSDIR should be set. For more information on this, see the reference towards the bottom of this article.

Multiple Platform Support

To developers creating application with ASP that aren't targeting an HTML client, the standard error page regularly provides no real use at all, and can cause problems if the data it provides is not in the correct format.

For instance, an alternative use for ASP is the creation of WAP sites, where the target language is WML. Whilst the syntax of this language is similar to HTML, several errors will be generated if the standard HTML error page was sent to the client.

The first of these errors would be due to the size of the page -WML pages are limited to just a couple of kilobytes. Although this could be easily remedied with the error page displaying a reduced amount of information, this wouldn't solve the more important issue - the document would have the wrong content type, and would not be a valid WML compliant document.

To add support for WML (and potentially for more languages), the error page must detect the client that is requesting the information. This can be achieved by making use of the HTTP_ACCEPT Server-Variable. This value stores a comma-separated list of data-formats that are accepted by the client. For IE (and most other HTML browsers), this list includes "*/*". If this value occurs, then the HTML error page can be displayed, otherwise the WML error page can be rendered instead. In more complex systems, the supported formats of the individual browsers can be checked.

The ASP required to support the WML error page would be something similar to:

If InStr(Request.ServerVariables.Item("HTTP_ACCEPT"), "*/*")>0 Then
  Response.Write "<?xml version='1.0'?>"
  Response.Write "<!DOCTYPE wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'
'http://www.wapforum.org/DTD/wml_1.1.xml'>" & vbcrlf
  Response.Write "<wml>" & vbcrlf
  Response.Write " <head>" & vbcrlf
  Response.Write "  <meta http-equiv='cache-control' content='must-revalidate'/>" & vbcrlf
  Response.Write "  <meta http-equiv='pragma' content='no-cache'/>" & vbcrlf
  Response.Write " </head>" & vbcrlf
  Response.Write "  <card id='Error' title='Error'>" & vbcrlf
  Response.Write "  <do type='prev' label='Back'><prev /></do>" & vbcrlf

  Response.Write "  <p>" & objASPError.Category & "</p>" & vbcrlf
  Response.Write "  <p>" & objASPError.Description & "</p>" & vbcrlf
  Response.Write "  <p>" & objASPError.ASPDescription & _
          ": Line " & objASPError.Line & "</p>" & vbcrlf

  Response.Write " </card>" & vbcrlf
  Response.Write "</wml>" & vbcrlf
End If

Rather than providing one-off implementations such as this, an XML document describing the error that has occurred could be generated. The type of document that the client accepts could then be detected, with a specific XSLT transformation being applied for each. This would allow for debugging of systems developed for CHTML and iMode browsers amongst others.

Further Extensions

As described earlier, the e-mail functionality could be extended to provide support for full development teams - sending messages to the relevant developers, and creating entries into a bug-tracking system automatically, and adding comments to source-controlled files.

To do this, meta-information would need to be stored in the source-file, containing such information as the developer's name/username, which application the code was part of (this could probably be calculated from the IIS application name), etc.

Although the text editor makes quick-fixes very easy to carry out, it is less functional than the most basic implementation of Notepad. The addition of a go-to-line function would certainly help a lot, and the ability to set tab-indents, highlight the code, and so on would make this a viable second-choice development environment when it is known that there are several errors that all need correcting across a site.

To implement such features, it would be necessary to replace the Textarea element with an Active-X edit control, Flash/Java applet, or other program based on a richer language than HTML. There are several editors on the market that have Active-X interfaces - enabling them to be embedded in compliant environments (e.g. Delphi, Visual Basic, C++).

These can also be embedded into web pages, and a simple piece of DHTML to set the content of a hidden field to the value of the Active-X control's text before posting the form back would ensure the remainder of the implementation would still function as before.

A further issue that could be addressed by this page is in the transmission of error codes to client browsers. Internet Explorer v5.0 and above has settings that are enabled by default to "Show Friendly HTTP Error Messages". These messages over-ride error pages that are sent from the server, replacing their content with fairly generic information regarding errors.

These "friendly" pages are only displayed if an error code (a status other than 200) is sent to the client with the web page. If no call is made to Response.Status in the error page to specify an error code, then the browser will always display the content that is returned from IIS.
blog comments powered by Disqus

- 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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials