Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 230149 - Last Review: June 29, 2004 - Revision: 3.2
How To Access Session and Application Variables from Within a Visual Basic Component
This article was previously published under Q230149
This article demonstrates how to access the session and application variables declared in your Active Server Pages (ASP) page from within a Visual Basic component.
A common scenario is reading user ID and passwords stored in session variables from within a component to avoid passing them as parameters. Note that your application becomes more scalable by avoiding state in Session (see the REFERENCES section in this article for more information). With this in mind, stress test your application before you move you application from development to production.
- Open a new ActiveX DLL project.
- Set a reference to the Microsoft Transaction Server (MTS) Type Library (Mtxas.dll).
- Set a reference to the Microsoft Active Server Pages Object library (Asp.dll).
- Rename the project as prjMTS and class as clsMTS.
- Copy the following code to the clsMTS:
Dim objApplication As Object
Dim objSession As Object
Public Function GetVar() As String
Dim objCtx As ObjectContext
Set objCtx = GetObjectContext
Set objApplication = objCtx.Item("Application")
Set objSession = objCtx.Item("Session")
GetVar = objApplication("Var1") & objSession("Var2") & "..."
End Function
- Create a blank new ASP page under one of virtual directories and add this code to it:
<%
Application("Var1") = "Where do you want"
Session("Var2") = "to go today ?"
Dim obj
Set obj = Server.CreateObject("prjMTS.clsMTS")
response.write obj.GetVar()
Set obj = Nothing
%>
- When you run this ASP page, the variables set in the page are accessed inside the Visual Basic component and the following appears in the browser:
Where do you want to go today ?
For additional information, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
175167Â
(http://kbalertz.com/Feedback.aspx?kbNumber=175167/EN-US/
)
How To Persisting Values Without Sessions
231282Â
(http://kbalertz.com/Feedback.aspx?kbNumber=231282/EN-US/
)
INFO: Stress Tools to Test Your Web Server
244457Â
(http://kbalertz.com/Feedback.aspx?kbNumber=244457/EN-US/
)
How To Debug an MTS Visual Basic Component Running Under ASP
APPLIES TO
- Microsoft Active Server Pages 4.0, when used with:
- Microsoft Internet Information Server 4.0
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
| kbaspobj kbcodesnippet kbhowto KB230149 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate