EX1.1. Create a new ActiveX DLL Project in Visual Basic.
2. 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) 3. Name the Project ObjectCtxtProject and name the Class ObjectCtxtClass.
4. Set the Class Property MTSTransactionMode = 1 - NoTransactions.
5. Copy and paste the following code into the Class Module:
[CODE]Implements ObjectControl Private objContext As ObjectContext Option Explicit 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() End Sub Private Function ObjectControl_CanBePooled() As Boolean ' This object should not be recycled, ' so return false. ObjectControl_CanBePooled = False End Function Private Sub ObjectControl_Deactivate() ' Perform any necessary cleanup here. Set objContext = Nothing End Sub[/CODE]
6. Copy and paste the following public method into the Class Module:
[CODE]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." Else objResponse.Write "Try Internet Explorer today!" End If End Sub[/CODE]
7. Compile the DLL.
8. Add the DLL to a MTS Server/Library Package. 9. Copy and paste the following ASP script into a new ASP file in a virtual directory.
[CODE]<% set obj = Server.CreateObject("ObjectCtxtProject.ObjectCtxtClass") obj.TestMethodObjectCtxt set obj = Nothing %>[/CODE]
10. 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! EX2.1. Open a new ActiveX DLL project.
2. Set a reference to the
Microsoft Transaction Server (MTS) Type Library (Mtxas.dll). 3. Set a reference to the
Microsoft Active Server Pages Object library (Asp.dll).
4. Rename the project as prjMTS and class as clsMTS.
5. Copy the following code to the clsMTS:
[CODE]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[/CODE]
6. Create a blank new ASP page under one of virtual directories and add this code to it:
[CODE]<% 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 %>[/CODE]
7. 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 ? 출처 : MSDN.com
주의1.)
Response, Request, Server, Application, Session 등의 asp 객체를 사용하고자 할경우 MTS 없이 사용하면 오류가 발생한다 .
이는 MTS 없이는 컴포넌트가 Context 를 관리할수 없기때문이며, 어떤 클라이언트에게 asp 구문을 수행해야 하는지 알길이 없기 때문이다 .
주의출처 : LikeJazz(박 상길) 님의 "COM+ 로 구현해보는 게시판 리스트 페이지" 강좌중...
주의2.)
Visual Basic ServicePack 이 설치가 되어야 한다.
테스트는 ServicePack 5, 6 두가지에서 테스트 완료 했다.