first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

VB Code: General Structure for an IIS Application

'Since I am very untrusting of VB 6 Web Classes, 'I start IIS Applications with an ActiveX DLL Project. 'I have one Class (called WebApp) 'that talks directly to the server 'and the other Classes support the WebApp Class. 'This is the code that builds WebApp: ' 'For more details about this technique please see 'MS KB article Q238274 '("Q238274 - HOWTO: Obtain ObjectContext with 'ObjectControl Inside VB COM DLL From ASP and MTS") ' 'and ' 'MSDN Article "Instancing for Classes Provided by ActiveX Components" '(http://msdn.microsoft.com/library/devprods/vs6/vbasic '/vbcon98/vbconinstancingforolecomponentclasses.htm) ' Implements ObjectControl

Private MTSObjectContext As MTxAS.ObjectContext Private ASPApplication As ASPTypeLibrary.Application Private ASPRequest As ASPTypeLibrary.Request Private ASPResponse As ASPTypeLibrary.Response Private ASPServer As ASPTypeLibrary.Server Private ASPSession As ASPTypeLibrary.Session

Private p_strHTML As String Private p_ADOrst As ADODB.Recordset

'These statements refer to the Classes that 'support" the WebApp Class:Public objHTML As HTMLServices Public objADO As ADOServices Public objExcel As ExcelServices Public objStr As StringServices Public objTextFile As TextFileHandler

Private Sub ObjectControl_Activate() 'The MTSObjectContext object variable is access to MTS. Set MTSObjectContext = MTxAS.GetObjectContext() Set ASPApplication = MTSObjectContext.Item("Application") Set ASPRequest = MTSObjectContext.Item("Request") Set ASPResponse = MTSObjectContext.Item("Response") Set ASPServer = MTSObjectContext.Item("Server")

'TIP: Avoid using the Session object for Stateless
'high performance.
'The @EnableSessionState Directive is set to False.
'If a Session is needed then uncomment this line:
'Set ASPSession = MTSObjectContext.Item("Session")

Set objHTML = _
    MTSObjectContext.CreateInstance(VB.App.EXEName _
        & ".HTMLServices")
'Note that we are using CreateInstance.
'To use VBA object-creation methods would instantiate 
'these objects outside of MTS context.

End Sub

Private Sub ObjectControl_Deactivate()

Set ASPApplication = Nothing
Set ASPRequest = Nothing
Set ASPResponse = Nothing
Set ASPServer = Nothing
Set ASPSession = Nothing

Set objHTML = Nothing

Set MTSObjectContext = Nothing

End Sub

Private Function ObjectControl_CanBePooled() As Boolean ObjectControl_CanBePooled = False End Function

Public Sub Command(Optional ByVal Cmd = vbNullString)

If ASPRequest.QueryString.Count > 0 Then
    Cmd = ASPRequest.QueryString.Item("Cmd")
End If

Select Case Cmd
    Case "SayHello"
        Call ASPResponse.Write(objHTML.GetPage("Hello World!"))
    Case Else
        p_strHTML = "<H1>IIS Web Application</H1>" & vbCrLf _
            & "<UL>" & vbCrLf _
            & VBA.Space$(4) & "<LI>Application Name: " _
            & App.ProductName & "</LI>" & vbCrLf _
            & VBA.Space$(4) & "<LI>Copyright: " _
            & VB.App.LegalCopyright & "</LI>" & vbCrLf _
            & VBA.Space$(4) & "<LI>Company Name: " _
            & VB.App.CompanyName & "</LI>" & vbCrLf _
            & VBA.Space$(4) & "<LI>Comments: " _
            & VB.App.Comments & "</LI>" & vbCrLf
        Call ASPResponse.Write(objHTML.GetPage(p_strHTML))
End Select

End Sub


What follows is the ASP code that calls the IIS Application:

<%@ EnableSessionState=False Language=VBScript %> <% Set obj = Server.CreateObject("Default.WebApp")

obj.Command()

%>

mod date: 2000-04-12T05:55:17.000Z