Using custom .net classes in ASP Classic Compiler

To use custom .net classes, I extended VBScript syntax with the Imports statement. The Imports statement introduce the top namespace to the VBScript, as in the example below. The following example demonstrates using ADO.NET in ASP Classic Compiler:

    imports system
    dim filePath = Server.MapPath("/Database/authors.mdb")
    dim oleConn = new"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath)

    dim cmd = new"SELECT * From authors", oleConn)
    dim dr = cmd.ExecuteReader()
    do while dr.Read()
        response.Write(dr.GetString(1) & "<br/>")

In the example above, “imports system” instructs that system is a namespace rather than an object. When encounters, it follows the namespace hierarchy to find the oledbconnection class.

However, does not automatically search all the loaded assemblies. Instead, it only searches the assemblies it was instructed search. will always search the system.dll assembly. However, to instruct to also search in the, we need to add the following code to global.asax.cs:

using System.Reflection;
using Dlrsoft.Asp;

protected void Application_Start(object sender, EventArgs e)
    Assembly a1 = Assembly.Load("System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089");

The above code tells AspHandler to search the System.Data.dll assembly for classes.

Lastly, to saves the typing of the fully qualified class name, the “imports” statement also supports alias. The following code demonstrates using alias to save typing:

imports t = system.text

dim sb = new t.StringBuilder()
sb.append(" is ")
sb.append(" stringbuilder!")
response.write sb.toString()


No Comments