明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

如何把ASP編寫(xiě)成DLL(2)

[摘要]現(xiàn)在,無(wú)論什么時(shí)候用戶(hù)訪問(wèn)一個(gè)帶有本組件的ASP文件,IIS就會(huì)把ScriptingContext傳送給我們的對(duì)象請(qǐng)我們使用.這個(gè)ScriptingContext包括了全部的ASP方法和屬性.實(shí)現(xiàn)上,這使得我們有能力訪問(wèn)所有ASP的對(duì)象.看下面的代碼:Public Sub OnStartPage(...
現(xiàn)在,無(wú)論什么時(shí)候用戶(hù)訪問(wèn)一個(gè)帶有本組件的ASP文件,IIS就會(huì)把ScriptingContext傳送給我們的對(duì)象請(qǐng)我們使用.這個(gè)ScriptingContext包括了全部的ASP方法和屬性.實(shí)現(xiàn)上,這使得我們有能力訪問(wèn)所有ASP的對(duì)象.看下面的代碼:

Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub

以后我們就能用在VB中用MyApplication 來(lái)代替ASP中的Application,同理可以代替Request,Server.....,不過(guò)我們來(lái)是要在 OnStartPage之前來(lái)申明這些變量:

Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session

使用ASP的對(duì)象
我們的變量現(xiàn)在就能像標(biāo)準(zhǔn)的ASP對(duì)象來(lái)使用了!比如,我們經(jīng)常在ASP中用Request.form()來(lái)收集提交表單的數(shù)據(jù).現(xiàn)在我們?cè)谖覀兊腣B中實(shí)現(xiàn)這個(gè)功能,代碼如下:

用ASP中實(shí)現(xiàn):
〈%
MyTempVariable = Request.Form("userName")
Response.Write ("you entered "& MyTempVariable & "as your user name")
%>

在VB中實(shí)現(xiàn):

MyTempVariable = MyRequest.Form("userName")
MyResponse.Write ("you entered "& MyTempVariable & "as your user name")

通過(guò)使用MyResponse來(lái)代替Response,我們能夠使用所有Response的方法,當(dāng)然,MyResponse這個(gè)名字可以隨便來(lái)取,你甚至可以就取Response.
另一件我們得注意