Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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

↑ Back to the top


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

↑ Back to the top


Keywords: KB323259, kbhowtomaster, kbwebforms

↑ Back to the top

Article Info
Article ID : 323259
Revision : 8
Created on : 8/19/2005
Published on : 8/19/2005
Exists online : False
Views : 665