Troy Forster's Wiki > ASP Classic Practices For The 21st Century

ASP Classic Practices For The 21st Century

Although VisualStudio 2010 is in it's second beta and ASP.Net 4.0 is imminent there are still many companies running some legacy applications on ASP Classic including mine.  Thankfully my role as architect and lead developer for special applications doesn't involve any programming on the Classic platform.  However, I do periodically provide guidance to the team supporting the legacy applications.  As such I have decided to document some of the general practices and recommendations here.

SOA As A Migration Strategy

Nobody really wants to actively support a 15 year old web framework however the realities of complexity, economics and scale often preclude a complete rewrite-migrate-deploy from Classic to .NET.  Yet clients continue to report bugs and request new features.  Service Oriented Architecture is one way to move cautiously to a new environment.  By implementing bugs and new featurs as web services and consuming them from a modified front end we can slowly separate a web application into layers.  These layers can later be duplicated into .NET and thoroughly tested before replacing their Classic counterparts.

This is exactly the approach that we have undertaken at adbeast.  About 30% of a legacy application has been re-written into a robust API with functionality grouped in VBScript pseudo classes.  A second team is following along and converting the VBScript pseudo classes to .NET classes.

JScript Is Far More Powerful Than VBScript

Microsoft provided two server languages from the very first release of ASP Classic.  The languages are VBScript and JScript, an implementation of JavaScript with additional objects to interact with ADO, WsH, etc.

Because of it's dynamic nature and prototypical inheritance JScript is actually far better suited as a server-side language than VBScript.  Unfortunately it has been traditionally downplayed in favour of VBScript, itself loosely based on Microsoft's once immensely popular VisualBasic desktop language.

Obviously nobody is going to rewrite their entire ASP Classic application in JScript.  If they had the resources to do that then they would obviously skip JScript and go directly to C# and the .NET platform.  But an often forgotten feature of ASP Classic is it's ability to support both languages simultaneously and allow function calls to be made between them.  The following example demonstrates VBScript code calling into a JScript function in the same ASP file.

<script language="vbscript" runat="server">
   Dim i: For i = 0 To 10
      Response.Write(fibonacci(i) & " ")

<script language="javascript" runat="server">
   function fibonacci(n) {
      var seed = 0;
      if (n == 0) return (seed);
      if (n == 1) {
         seed += 1;
         return (seed);
      else {
         return (fibonacci(n - 1) + fibonacci(n - 2));

Because we can intermix JScript we can selectively replace existing VBScript functionality for bug fixes and create new features in whichever language we choose.  But why would we really want to do this? After all, the example above could just as easily been coded in 100% VBScript.  Some compelling reasons I have come up with so far include:

JScript supports wider integers

The width of a VBScript integer is -32,768 to 32,767.  While VBScript supports longs and doubles only integers maybe used in boolean operations. 

If you have a flags structure the maximum number of flags supported is 14 (2^14 = 16384, where as 2^15 = 32,768 or greater than the maximum size of an integer).  If your flags structure requires more than 14 flags you can no longer use a simple boolean function.

You can however implement a JavaScript function to do the boolean calculation and pass longs or doubles into it.

function isBitSet(value, bit) {
   return ((value & bit) == bit);

JScript classes can be used in VBScript

VBScript has a structure called a class but it's far different than the classes found in Java, C# and JavaScript.  VBScript pseudo classes are exceedingly verbose, don't support inheritance and are mostly two-dimensional.

This next example shows how we can create a pet object with a couple of string properties plus a property containing an array of nested objects.  We then read the property values using simple dot-notation.

<script language="vbscript" runat="server">
   dim dog: Set dog = pet
   Response.Write("My pet's name is " & & " and is a " & dog.species & ". " & & " has a brother named " & dog.siblings.get(0).brother)
   Set dog = Nothing

<script language="javascript" runat="server">
   pet = {
      species : "dog",
      name : "rex",
      siblings : [{ "brother": "rover" }, { "sister": "daisy"}]
   if (!Array.prototype.get) {
      Array.prototype.get = function(prop) {
         return this[prop];

The code that extends the Array prototype is necessary because JavaScript and VBScript arrays are not compatible with each other.  VBScript arrays are simple structures with few features where as JavaScript arrays are actually JavaScript objects.  By extending the JavaScript Array prototype with a simple enumerator we are able to provide access to the array elements to VBScript.

There Is No Such Thing As VBSON

In order to support SOA in a web application it's almost certain that Ajax is going to be employed to talk to the services layer.  We could use SOAP to pass data between the server and browser but that would require a hefty XML library on both sides to serialize and deserialize the packets.  Today's almost ubiquitous answer to that problem is JSON and just about every server platform now has one or more excellent JSON libraries. 

That is except ASP Classic.  The libraries that do exist tend to be clunky and make heavy use of the Dictionary object for both serialization and deserialization.  All the libraries I have found to date are built using VBSCript which is incapable of emitting either JSON or VBSON.  This is another perfect use-case for JScript. 

See my implementation of Douglas Crockford's json2.js for converting objects to and from JSON within VBScript.

Tag page
Viewing 1 of 1 comments: view all
The JScript is the newest script for 21st century. And I think it will have a long way for more programs. Articles and some essays said that, it is the newest trend for making scripts. I, myself is beginning to use this script.
Posted 00:39, 29 Dec 2009
Viewing 1 of 1 comments: view all
You must login to post a comment.