Asp組件中級入門與精通系列之三

來源:互聯網
上載者:User

Session相比較就簡單多了

開啟vb6,建立Activex Dll工程。工程名修改為fCom,類名修改為fZ3
引用“Microsoft Active Server Pages Object”物件程式庫。
建立兩個組件事件:OnStartPage以及OnEndPage
在事件OnStartPage中建立類ScriptingContent的一個引用。
執行個體化類ScriptingContent。

?

代碼如下:

Option Explicit

?

'對象的聲明

Dim myResponse As Response

Dim myRequest As Request

Dim myApplication As Application

Dim myServer As Server

Dim mySession As Session

?

??? '當組件被建立的時候會觸發這個事件

Public Sub OnStartPage(myScriptingContent As ScriptingContext)

???? '進行對象的執行個體化

???? Set myResponse = myScriptingContent.Response

???? Set myRequest = myScriptingContent.Request

???? Set myServer = myScriptingContent.Server

???? Set myApplication = myScriptingContent.Application

???? Set mySession = myScriptingContent.Session

End Sub

?

??? '當組件被銷毀的時候觸發這個事件

Public Sub OnEndPage()

???? '銷毀對象

???? Set myResponse = Nothing

???? Set myRequest = Nothing

???? Set myServer = Nothing

???? Set myApplication = Nothing

???? Set mySession = Nothing

End Sub

?

‘可以看到,把以前asp中寫的搬到了vb中,寫法是一樣的

‘得到所有的session的變數和值

Public Sub ShowSession()

'可以設定逾時20分鐘

??? mySession.Timeout = 20

??? Dim myitem

??? '得到所有的session

??? For Each myitem In mySession.Contents

??????? myResponse.Write myitem & ": " & mySession.Contents(myitem)

??????? myResponse.Write "
"

??? Next

End Sub

?

測試

開啟visual interdev6.0,產生一個asp檔案

dim obj

set obj=server.CreateObject("fcom.fz3")

session("name")="龍捲風"

session("age")=26

session("特長")="組件"

obj.ShowSession()

%>

?

配置好虛擬目錄,在ie中執行此asp檔案,可以看到

name: 龍捲風
age: 26
特長: 組件

?

Session的用法就講到這裡。Session其他的用法類似。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.