Microsoft KB Archive/323259

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

Article ID: 323259

Article Last Modified on 8/19/2005

-

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

-



This article was previously published under Q323259





For a Microsoft Visual C# .NET version of this article, see 810928.



For a Microsoft Visual Basic .NET version of this article, see 319429.



IN THIS TASK

 * SUMMARY
 * Requirements
 * Create a Visual Basic Component
 * Add the Visual Basic Component to Component Services
 * Test the Component on an ASP.NET Page
 * REFERENCES



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

Requirements

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

back to the top

Create a Visual Basic Component
To create a Visual Basic 6.0 COM component:  In Visual Basic 6.0, create a new ActiveX DLL project. On the Project menu, click References. 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. Change the project name to ObjectCtxtProject, and then change the class name to ObjectCtxtClass . On the Project menu, click ObjectCtxtProject Properties.</li> Click to select the Unattended Execution and Retained In Memory check boxes, and then click OK.</li>  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(&quot;Application&quot;) ' Obtain ASP Application object. Set objSession = objContext(&quot;Session&quot;)     ' Obtain ASP Session object. Set objResponse = objContext(&quot;Response&quot;)   ' Obtain ASP Response object. Set objRequest = objContext(&quot;Request&quot;)     ' Obtain ASP Request  object.

'This code uses the Response object (objResponse). 'You can use other intrinsic objects in a similar fashion. objResponse.Write &quot;Hello World!&quot; End Sub </li> On File menu, click Make ObjectCtxtProject.dll to create the DLL.</li></ol>

back to the top

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.

back to the top

Test the Component on an ASP.NET Page
To test the component: <ol>  In Notepad or another text editor, paste the following code: <%@ Page aspcompat=true %> <%      Dim obj As Object obj = Server.CreateObject(&quot;ObjectCtxtProject.ObjectCtxtClass&quot;) obj.TestMethodObjectCtxt obj = Nothing %>                        </li> Save the text file with the .aspx file name extension in the virtual folder of a Microsoft Internet Information Services (IIS) Web application.</li> Open Microsoft Internet Explorer, and then open the .aspx page. You see text that reads &quot;Hello World!&quot;</li></ol>

back to the top

<div class="references_section">