HOW TO: Access ASP.NET Intrinsic Objects in a Visual Basic 6.0 Component

This article was previously published under Q323259
This article has been archived. It is offered "as is" and will no longer be updated.
For a Microsoft Visual C# .NET version of this article, see 810928.
For a Microsoft Visual Basic .NET version of this article, see 319429.
This step-by-step article describes how to access ASP.NET intrinsic objects in a Microsoft Visual Basic Component Object Model (COM) component.


  • Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, or Windows XP Professional
  • Microsoft Internet Information Services (IIS)
  • Microsoft .NET Framework

Create a Visual Basic Component

To create a Visual Basic 6.0 COM component:
  1. In Visual Basic 6.0, create a new ActiveX DLL project.
  2. On the Project menu, click References.
  3. In the References dialog box, click to select theCOM+ Services Type Library (Comsvcs.dll) and Microsoft Active Server Pages Object Library (Asp.dll) check boxes, and then click OK.
  4. Change the project name to ObjectCtxtProject, and then change the class name to ObjectCtxtClass.
  5. On the Project menu, click ObjectCtxtProject Properties.
  6. Click to select the Unattended Execution and Retained In Memory check boxes, and then click OK.
  7. Add the following code to the ObjectCtxtClass class:
    Public Sub TestMethodObjectCtxt()        Dim objContext As ObjectContext        Dim objResponse As Response        Dim objRequest  As Request        Dim objApplication  As Application        Dim objSession As Session        Set objContext = GetObjectContext()                    Set objApplication = objContext("Application") 	' Obtain ASP Application object.        Set objSession = objContext("Session") 		' Obtain ASP Session object.        Set objResponse = objContext("Response") 	' Obtain ASP Response object.        Set objRequest = objContext("Request")   	' Obtain ASP Request  object.        'This code uses the Response object (objResponse).        'You can use other intrinsic objects in a similar fashion.        objResponse.Write "Hello World!"      End Sub
  8. On File menu, click Make ObjectCtxtProject.dll to create the DLL.

Add the Visual Basic Component to Component Services

To add the Visual Basic component to Component Services:
  1. On the Start menu, point to Settings, and then click Control Panel.
  2. Double-click Administrative Tools, and then double-click Computer Management.
  3. Expand Component Services , expand Computer, expand My Computer, and then expand COM+ Applications.
  4. Right-click COM+ Applications, point to New, and then click Application.
  5. In the COM+ Application Install Wizard, click Next.
  6. On the Install or Create a New Application page, click Create an empty application.
  7. In the text box, type AspCtxTest. Click Next two times, and then click Finish.
  8. In the console tree, under COM+ Applications, expand AspCtxTest node, and then click Components.
  9. Drag the ObjectCtxtProject.dll file from Windows Explorer to the right pane of the Microsoft Management Console (MMC). This registers the ObjectCtxtProject.dll file in Component Services.

Test the Component on an ASP.NET Page

To test the component:
  1. In Notepad or another text editor, paste the following code:
    <%@ Page aspcompat=true %><%       Dim obj As Object        obj = Server.CreateObject("ObjectCtxtProject.ObjectCtxtClass")       obj.TestMethodObjectCtxt       obj = Nothing%> 						
  2. Save the text file with the .aspx file name extension in the virtual folder of a Microsoft Internet Information Services (IIS) Web application.
  3. Open Microsoft Internet Explorer, and then open the .aspx page. You see text that reads "Hello World!"
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
238274 HOWTO: Obtain ObjectContext with ObjectControl Inside VB COM DLL From ASP and MTS

Article ID: 323259 - Last Review: 02/27/2014 21:13:31 - Revision: 2.6

  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • kbnosurvey kbarchive kbwebforms kbhowtomaster KB323259