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

Article translations Article translations
Article ID: 323259 - View products that this article applies to.
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.
Expand all | Collapse all

On This Page

This step-by-step article describes how to access ASP.NET intrinsic objects in a Microsoft Visual Basic Component Object Model (COM) component.

Requirements

  • 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!"

REFERENCES

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

Properties

Article ID: 323259 - Last Review: February 27, 2014 - Revision: 2.6
APPLIES TO
  • 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
Keywords: 
kbnosurvey kbarchive kbwebforms kbhowtomaster KB323259

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com