How To Access Active Server Pages Intrinsic Objects Within a Visual Basic COM Component (299634)



The information in this article applies to:

  • Microsoft Active Server Pages, when used with:
    • the operating system: Microsoft Windows 2000 SP1
    • the operating system: Microsoft Windows 2000 SP2
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0

This article was previously published under Q299634

SUMMARY

This step-by-step procedure demonstrates how to access Active Server Pages (ASP) intrinsic objects within a Microsoft Visual Basic Component Object Model (COM) component.

back to the top

Step-by-Step Example

  1. Create a new ActiveX DLL project in Visual Basic.
  2. From the Project menu, click References, and then select the COM+ Services Type Library (Comsvcs.dll) and Microsoft Active Server Pages Object Library (Asp.dll) check boxes.
  3. Type ObjectCtxtProject for the project name, and type ObjectCtxtClass for the class name. While in Project Properties, select the retained in memory and unattended execution options.
  4. Copy and paste the following public method into the ObjectCtxtClass module:
    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
    					
  5. From the File menu, click Make ObjectCtxtProject.dll to compile the dynamic-link library (DLL).
  6. On the Microsoft Windows Start menu, point to Programs, point to Administrative Tools, and then click Component Services to start the Microsoft Management Console (MMC) for Component Services.
  7. Under Console Root, click to expand the Component Services, Computers, My Computer, and COM+ Applications nodes.
  8. Select and then right-click COM+ Applications. In the resultant shortcut menu, point to New, and then click Application.
  9. In the COM Application Install Wizard, click Next. On the Install or Create a New Application page, click Create an empty application, and type AspCtxTest in the text box. Click Next twice, and then click Finish.
  10. Under COM+ Application, click to expand the AspCtxTest node, and then click Components.
  11. From Windows Explorer, drag the compiled DLL, and drop it onto the right pane of the MMC. This registers the DLL with Component Services.
  12. In any text editor, copy and paste the following ASP script:
    <%
           set obj = Server.CreateObject("ObjectCtxtProject.ObjectCtxtClass")
           obj.TestMethodObjectCtxt
           set obj = Nothing
    %>
    					
  13. Save this ASP file in a virtual folder that is a Microsoft Internet Information Server (IIS) Web application.
  14. In your Web browser, run the ASP page. The text, "Hello World!", should appear.
back to the top

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

230149 How To Access Session and Application Variables from Within a Visual Basic Component

238274 How To Obtain ObjectContext with ObjectControl Inside VB COM DLL from ASP and MTS

back to the top

Modification Type:MinorLast Reviewed:7/15/2004
Keywords:kbhowto kbHOWTOmaster KB299634 kbAudDeveloper