Managing Legacy Classic ASP Websites

In the 10 years since ASP.NET 1.0 was first released, all Classic ASP websites will have been converted to ASP.NET, right? 


Like it or not, legacy systems are still with us and they are likely to be with us for some time yet. As developers, it's a fairly reasonable assumption that we want all systems to utilize the latest technology, and converting Classic ASP websites to either ASP.NET 4.0 or ASP.NET MVC3 Web Applications will be a logical step. There's just one problem; return on investment.

Many if not most businesses will be feeling the pinch right now, and the return on investment in time and resources to convert Classic ASP websites may well be difficult to see for financial managers. The improved manageability, stability, testing, etc, that comes from using the latest technologies will be negated by managers watching the bottom line very carefully. If the investment on conversion doesn't make an improvement to the bottom line, or someone else isn't willing to pay for the conversion (for example if you are an agency and the client wants to pay for you to convert), then full conversion is probably a no-go.

A halfway house solution to this problem is to utilise the managability features of ASP.NET and Visual Studio Web Projects, but keep the Classic ASP code the same with one or two exceptions. Why do this? Well:

1. It allows you to better manage the source code within a web project, allowing you to use all Visual Studio features applicable to web application projects

2. You can leverage the power of web.config transformations for different builds (I'll come on to that in a bit!)

3. New sections in your web application can be developed can be developed using ASP.NET - whilst this creates a hybrid application, it may very well be quicker and therefore cheaper to develop the new sections in ASP.NET depending on the skill set of the developers in your company. I used to use VBScript day in, day out for years but I struggle now compared with how quick I can write code in C# or VB.NET.

Reading the Web Config File

To read the web.config file in your new project containing your ASP code, you will need to create a function that iterates through the web.config file and returns the value for the key you are looking for.

The code for this function is quite simple:

Function GetConfigurationValue(Name)
    Dim returnString
    Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
    Set xmlAppSettings = server.CreateObject("Microsoft.XMLDOM")
    Set xmlAdd = server.CreateObject("Microsoft.XMLDOM")
    xmlDoc.async = "false"
    xmlDoc.load(server.MapPath ("web.config"))
    Set xmlAppSettings = xmlDoc.GetElementsByTagName("appSettings").Item(0)
    Set xmlAdd = xmlAppSettings.GetElementsByTagName("add")
    For Each x In xmlAdd
        'Check for the Atrribute Value
        If  x.getAttribute("key") = Name Then
            returnString  = x.getAttribute("value")
        End If
    GetConfigurationValue = returnString 
End Function


This function can then be called like so: <% GetConfigurationValue("TestKey")%> - this will iterate through the web.config file and return the value for the TestKey appSettings key.

You can download a sample project from here. This project has one Classic ASP file, and contains a sample use of the function above.


  1. I was on classic asp JScript for too long. Now everything I do is Node JS with iisnode on IIS. I think now migrating from Classic ASP to Node JS, especially if you did ASP JScript, is just as logical.


Post a Comment

Popular posts from this blog

Connecting to SQL Azure with Dynamic IP Addresses

HTML to PDF Conversion in MVC 4

WebAPI and Subscriber Authentication by Custom HTTP Headers