Using Classic ASP Components in ASP.NET - Early Binding

While it is easy to use ASP components in ASP.NET using late binding - calling the component with Server.CreateObject - it is more efficient to use early binding. To do this, a .NET Framework equivalent assembly must be created using the TLBIMP tool, supplied with the .NET Framework. This assembly is a DLL which acts as a wrapper around the ASP component.

First, register the ASP component. Then run TLBIMP.exe at the command prompt, or from the Run box in the Start Menu. The syntax is:

TLBIMP ComponentName.dll /out:NewName.dll

Full physical paths are required for both DLLs. The new DLL needs to be put in the website's BIN directory. It can either be created in this directory or moved after creation.

The script that calls the component must import the Framework equivalent assembly as a Namespace. The component instance is created using the following VB.NET syntax:

Dim ObjName As New ClassNameClass()

ObjName is the name of the object instance and ClassName is the name of the class in the ASP component.

Example:

Here is an example using our csImageFile component, which we will assume is registered and in a directory called "c:\components". Run TLBIMP at the command prompt to create the wrapper DLL.

tlbimp c:\components\csimagefile64.dll /out:c:\inetpub\wwwroot\bin\csifnet.dll

This assumes that the BIN directory for the website is at "C:\inetpub\wwwroot\bin" and it names the new DLL "csifnet.dll". This file could be created in a different directory and moved to the BIN directory later. The ASP component has its location stored in the registry when it is registered and this should not be moved without unregistering it first.

The script using the command must import the wrapper as a Namespace:

<%@ Import NameSpace = "csifnet" %>

The script creates an instance of the object. The name used for the class has the word "Class" appended to it by the wrapper DLL. So for our csImageFile component, the full class ID is "csImageFile.Manage" so the .NET class name is "ManageClass"

Dim Image As New ManageClass()

The rest of the script can continue in the same way as for a late bound script. Here is a full script that generates an image containing a piece of text.

<%@ Page language="vb" debug=true %>
<%@ Import NameSpace = "csifnet" %>
<%
Response.Expires = 0
Response.Buffer = true
Response.Clear

Dim Image As New ManageClass()

Image.NewImage(150, 50, "00ff00")
Image.TextOpaque = false
Image.TextSize = 22
Image.Text(5, 10, "Sample image")

Dim OutArray As Array = Image.GIFData
Dim ByteArray(OutArray.Length - 1) As Byte
Array.Copy(OutArray, ByteArray, OutArray.Length)
Response.ContentType = "image/gif"
Response.BinaryWrite(ByteArray)
%>

The available methods and properties of the component, and the class name, can all be found by opening the wrapper DLL using the ILDASM.EXE tool that is also supplied with the .NET Framework.

Streaming to the browser is slightly different in C#, and the code used would be:

Array OutArray = (Array)(Image.GIFData);
Byte[] ByteArray = new Byte[OutArray.Length];
Array.Copy(OutArray, ByteArray, OutArray.Length);
Response.ContentType = "image/gif";
Response.BinaryWrite(ByteArray);

64 Bit Operating Systems

All our ASP components are now available as both 32 bit and 64 bit. If you want to use one of the older 32 bit versions on a 64 bit system it must be added to a COM+ Application in component services.

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.