Microsoft KB Archive/299634

= How To Access Active Server Pages Intrinsic Objects Within a Visual Basic COM Component =

Article ID: 299634

Article Last Modified on 7/15/2004

-

APPLIES TO

 Microsoft Active Server Pages 4.0, when used with:  Microsoft Windows 2000 Service Pack 1

 Microsoft Windows 2000 Service Pack 2  Microsoft Visual Basic 5.0 Enterprise Edition Microsoft Visual Basic 6.0 Enterprise Edition Microsoft Visual Basic 5.0 Learning Edition</li> Microsoft Visual Basic 6.0 Learning Edition</li> Microsoft Visual Basic 5.0 Professional Edition</li> Microsoft Visual Basic 6.0 Professional Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q299634

<div class="notice_section">

IN THIS TASK
SUMMARY
 * Step-by-Step Example

REFERENCES

<div class="summary_section">

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
<ol> Create a new ActiveX DLL project in Visual Basic.</li> 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.</li> 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.</li>  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(&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> From the File menu, click Make ObjectCtxtProject.dll to compile the dynamic-link library (DLL).</li> 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.</li> Under Console Root, click to expand the Component Services, Computers, My Computer, and COM+ Applications nodes.</li> Select and then right-click COM+ Applications. In the resultant shortcut menu, point to New, and then click Application.</li> 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.</li> Under COM+ Application, click to expand the AspCtxTest node, and then click Components.</li> From Windows Explorer, drag the compiled DLL, and drop it onto the right pane of the MMC. This registers the DLL with Component Services.</li>  In any text editor, copy and paste the following ASP script: <%      set obj = Server.CreateObject(&quot;ObjectCtxtProject.ObjectCtxtClass&quot;) obj.TestMethodObjectCtxt set obj = Nothing %>                   </li> Save this ASP file in a virtual folder that is a Microsoft Internet Information Server (IIS) Web application.</li> <li>In your Web browser, run the ASP page. The text, &quot;Hello World!&quot;, should appear.</li></ol>

back to the top

<div class="references_section">