Let's learn to look at the response object. In fact, we have been using the Write method of this object in previous tutorials.
Here we use the Response object to set cookies.
?
Open VB6 and create a new ActiveX DLL project. The project name is modified to fcom and the class name is modified to fZ5
references the Microsoft Active Server Pages Object Library.
Create two component events: OnStartPage and OnEndPage
creates a reference to the class Scriptingcontent in the event OnStartPage.
Instantiate class Scriptingcontent.
?
The
code is as follows:
Option Explicit
' object's declaration
Dim Myresponse as Response
Dim myrequest as Request
Dim MyApplication as Application
Dim MyServer as Server
Dim MySession as session
?
??? ' Triggers this event when the component is created
public Sub OnStartPage (myscriptingcontent as ScriptingContext)
???? ' To instantiate the object
???? Set myresponse = Myscriptingcontent.response
???? Set myrequest = Myscriptingcontent.request
???? Set myServer = Myscriptingcontent.server
???? Set MyApplication = myscriptingcontent.application
???? Set mysession = myscriptingcontent.session
End Sub
?
??? ' Triggers this event when the component is destroyed
public Sub onendpage ()
???? ' Destroy Object
???? Set myresponse = Nothing
???? Set myrequest = Nothing
???? Set MyServer = Nothing
???? Set MyApplication = Nothing
???? Set mysession = Nothing
End Sub
?
' Set cookies from the page,
in the component
public Sub GetCookie ()
??? Dim myitem
??? ' All information
??? For Each myitem in Myrequest.cookies
??????? Myresponse.write myitem & ":" & MyRequest.Cookies.Item (myitem)
??????? Myresponse.write "
"
??? Next
???
??? ' Single information
??? Myresponse.write "Where the user name is" & ":" & Myrequest.cookies ("username")
??? Myresponse.write "
"
??? Myresponse.write "Where the user Age is &:" & Myrequest.cookies ("aged")
??? Myresponse.write "
"
End Sub
' component to set cookies in the page to get
public Sub Setcookie ()
??? Myresponse.cookies ("com_username") = "Tornado"
??? Myresponse.cookies ("com_age") = 26
??? Myresponse.expires = #9/13/2004#
End Sub
?
is compiled into a DLL file and the system registers automatically.
otherwise manually registered Regsvr32 F:\test\fcom.dll
?
Test
turns on visual interdev6.0 to generate a fz5.asp file
?
configured the virtual directory, in IE to execute fc5.asp files, you can see
Tornado
26
age:26
Username: Tornado
com_age:26
Com_username: Tornado
where the user name is: Tornado
The user age is: 26
not to be continued