Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Two ways to access ASP objects from within a component

Total Hit ( 8870)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can write ASP components that work under any version of IIS by adding a special public method, named OnStartPage, to the public class module of the ActiveX DLL project. This method is then called by IIS whenever a script instantiates an object through the Server.CreateObject command. This is the code that does the trick:

Click here to copy the following block
Dim Request As ASPTypeLibrary.Request
Dim Response As ASPTypeLibrary.Response
Dim Server As ASPTypeLibrary.Server
Dim Session As ASPTypeLibrary.Session
Dim Application As ASPTypeLibrary.Application

' this method is called when the object is instantiated
' in the context of the ASP script

Public Sub OnPageStart(AspSC As ASPTypeLibrary.ScriptingContext)
  ' save variables pointing to main ASP objects
  Set Request = AspSC.Request
  Set Response = AspSC.Response
  Set Server = AspSC.Server
  Set Session = AspSC.Session
  Set Application = AspSC.Application
End Sub

' this method is called when IIS is about to destroy the object,
' after completing the processing of the ASP page.

Public Sub OnPageEnd()
  ' add here the code to be processed *after* the script
  ' in the ASP has completed its execution
End Sub

However, under IIS 5 (and IIS 4 under MTS) you should build your ASP components without using the OnStartPage method. Instead, you should retrieve the reference to the five main ASP objects using the ObjectContext object and the GetObjectContext method, as follows.
Dim Request As ASPTypeLibrary.Request
Dim Response As ASPTypeLibrary.Response
Dim Server As ASPTypeLibrary.Server
Dim Session As ASPTypeLibrary.Session
Dim Application As ASPTypeLibrary.Application

Private Sub Class_Initialize()
  Dim objCtx As ObjectContext
  Set objCtx = GetObjectContext
  Set Request = objCtx.Item("Request")
  Set Response = objCtx.Item("Response")
  Set Server = objCtx.Item("Server")
  Set Session = objCtx.Item("Session")
  Set Application = objCtx.Item("Application")
End Sub

Note that, regardless of the method you have chosen to get a reference to the main ASP object, in the end you have five class level variables with the same names as the ASP object they point to. This is intentional, because you can now easily move code from the ASP script (in VBScript) to the VB component, and back.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.