Using VB.NET Objects in regular ASP Pages

Using a VB.NET object in an ASP page can be accomplished with COM-Interop. While the whole interop mechanism can be complex depending on what you want to do, below is a basic example that should get you started.

1. Create a file called Class1.vb and placed this code in it:

Public Class SampleClass

    Public Function GetMyName() As String

        Return "This is from the .NET component"

    End Function

End Class


2. Create a keyfile with the strong name (sn) utility:
sn -k demokey.snk
3. Compile the VB app with:
vbc /t:library /keyfile:demokey.snk class1.vb
4. Install the library into the GAC with:
gacutil -i class1.dll
5. Use RegAsm to register it as a COM class:
regasm /tlb:class1.tlb class1.dll
Test it in ASP with:

<%
set x = server.CreateObject("SampleClass")
response.Write x.GetMyName()
%>

No Comments