This is extremely useful if you would like to have direct access to the ASP intrinsic objects; for example, Application, Session, Response, Request, and Server.
In IIS 3.0, components access ASP built-in objects through the IScriptingContext interface. Components that need to access the built-in objects do so through page-level event methods. While this method is still supported, an alternative now exists and is recommended as an improvement over page-level event methods.
Instead, use the ObjectContext Object to access the built-in objects. ObjectContext makes IIS applications better suited for large-scale scenarios and provides support for transaction processing. It is highly recommended that you convert your existing ASP-based applications to this new approach if they are high-volume applications. This conversion is required if your applications support transaction processing.
Implement the ObjectControl interface when you want to define context-specific initialization and cleanup procedures for your MTS objects and specify whether or not the objects can be recycled.
The ObjectControl interface provides the following methods:
- Activate: Allows an object to perform context-specific initialization whenever it's activated. This method is called by the MTS run-time environment before any other methods are called on the object.
- CanBePooled: Allows an object to notify the MTS run-time environment of whether it can be pooled for reuse. Return True if you want instances of this component to be pooled, or False if not.
- Deactivate: Allows an object to perform whatever cleanup is necessary before it's recycled or destroyed. This method is called by the MTS run-time environment whenever an object is deactivated.
- Create a new ActiveX DLL Project in Visual Basic.
- Select References from the Project menu and add the following references to the project:'Microsoft Transaction Server Type Library' (MTXAS.DLL)
'Microsoft Active Server Pages Object Library' (ASP.DLL)
- Name the Project ObjectCtxtProject and name the Class ObjectCtxtClass.
- Set the Class Property MTSTransactionMode = 1 - NoTransactions.
- Copy and paste the following code into the Class Module:
Private objContext As ObjectContext
Private Sub ObjectControl_Activate()
' Get a reference to the object's context here,
' so it can be used by any method that may be
' called during this activation of the object.
Set objContext = GetObjectContext()
Private Function ObjectControl_CanBePooled() As Boolean
' This object should not be recycled,
' so return false.
ObjectControl_CanBePooled = False
Private Sub ObjectControl_Deactivate()
' Perform any necessary cleanup here.
Set objContext = Nothing
- Copy and paste the following public method into the Class Module:
Public Sub TestMethodObjectCtxt()
Dim objResponse As Response
Dim objRequest As Request
Set objResponse = objContext("Response") ' Obtain ASP Response object
Set objRequest = objContext("Request") ' Obtain ASP Request object
If InStr(objRequest.ServerVariables("HTTP_USER_AGENT"), "MSIE") > 0 Then
objResponse.Write "You are using a very powerful browser."
objResponse.Write "Try Internet Explorer today!"
- Compile the DLL.
- Add the DLL to a MTS Server/Library Package.
- Copy and paste the following ASP script into a new ASP file in a virtual directory.
set obj = Server.CreateObject("ObjectCtxtProject.ObjectCtxtClass")
set obj = Nothing
- Request the ASP file from a browser, you will see the following result if you are running Internet Explorer: You are using a very powerful browser.Otherwise you will see the following result:Try Internet Explorer today!
ID d'article : 238274 - Dernière mise à jour : 19 nov. 2008 - Révision : 1