查看: 13  |  回复: 0
  ASP 从组件中访问ASP对象的两种方法
楼主
发表于 2025年8月31日 12:20
<%
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
%>


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com