|
Executing APG Scripts in Active Server Pages |
|
See Also: |
When running an APG script in an ASP page, it can be useful for the APG script to access the ASP objects. For example, values stored in the ASP Application object may be relevant to the APG script, as may data in the Request object.
Access to ASP objects can also minimize the effort required to convert existing ASP code. If you wish to optimize existing ASP pages, it may be desirable to leave most ASP object references as is, instead of converting ASP object references to their APGen equivalent. For help converting existing ASP code, see the ASPToAPG Example.
APGen 2.0 and later provides access to ASP objects via the ObjectContext object.
This include file enables access to ASP objects from within an APG script:
<%#
'------------------------------------------------------
' i_UseASPObjects.vbs.apg
'
' Description: #include this file in an APG script to
' use ASP objects in the script.
'
' IMPORTANT: The APG script must be run from an ASP
' page, otherwise the ASP objects won't be present in
' the ObjectContext.
'------------------------------------------------------
Dim bInASP, Request, Response, Session, Application, Server
' Grab the ASP Request object
Set Request =
ObjectContext("Request")
If IsEmpty(Request) Then
' We're not running within ASP
bInASP =
False
Else
' We're running within ASP
bInASP = True
' Grab the other ASP objects
Set
Response =
ObjectContext("Response")
Set
Session =
ObjectContext("Session")
Set Application = ObjectContext("Application")
Set
Server =
ObjectContext("Server")
End If
#%>
When the include file is #included in an APG script, ASP objects can be used in APG script blocks:
<!-- #include apg="i_UseASPObjects.vbs.apg" -->
<%#
Dim sAppPath
sAppPath =
Request.ServerVariables("APPL_PHYSICAL_PATH")
#%>
Note that the ASP objects are only present when the APG script is run from an ASP page. Here is a simple ASP snippet for running an APG script:
<%
Dim oAPGen
Set oAPGen =
Server.CreateObject("APGen")
oAPGen.Run Server.MapPath("script.apg")
%>
Note that the APGen object must be created using
Server.CreateObject(), not the VBScript CreateObject() function.
Server.CreateObject() propagates the caller's COM+/MTS ObjectContext to the
created object. VBScript's CreateObject() and JScript's
New ActiveXObject do not propagate the caller's
ObjectContext, which would prevent the APG script from accessing the ASP
objects.
For a more advanced example of running an APG script in an ASP page, see APG Script Status Reporting in ASP.