Let's take a look at the response object. In fact, we have been using the write method of this object in the previous tutorial.
Here we use the response object to set the cookie.
?
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to fz5
Reference the "Microsoft Active Server Pages object" Object Library.
Create two component events: onstartpage and onendpage
Create a reference of the scriptingcontent class in the event onstartpage.
Instantiation class scriptingcontent.
?
The Code is as follows:
Option explicit
'Object Declaration
Dim myresponse as response
Dim myrequest as request
Dim myapplication as application
Dim myserver as server
Dim mysession as session
?
??? 'This event is triggered when the component is created.
Public sub onstartpage (myscriptingcontent as scriptingcontext)
???? '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
?
??? 'This event is triggered 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 the cookie from the page.
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 "in which the user name is" & ":" & myrequest. Cookies ("username ")
??? Myresponse. Write"
"
??? Myresponse. Write "in which the user's age is" & ":" & myrequest. Cookies ("Age ")
??? Myresponse. Write"
"
End sub
'Set the cookie in the component.
Public sub setcookie ()
??? Myresponse. Cookies ("com_username") = "tornado"
??? Myresponse. Cookies ("com_age") = 26
??? Myresponse. expires = #9/13/2004 #
End sub
?
The system automatically registers the DLL file.
Otherwise, manually register regsvr32 F:/test/fcom. dll.
?
Test
Open visual interdev6.0 and generate a fz5.asp File
Dim OBJ
Set OBJ = server. Createobject ("fcom. fz5 ")
Call obj. setcookie ()
Response. Write Request. Cookies ("com_username ")
Response. Write"
"
Response. Write Request. Cookies ("com_age ")???
Response. Write"
"
?
'Set the cookie in the page below
Response. Cookies ("username") = "tornado"
Response. Cookies ("Age") = 26
Call obj. getcookie ()
?
%>
?
Configure the virtual directory and execute the fc5.asp file in IE. You can see
Tornado
26
Age: 26
Username: tornado
Com_age: 26
Com_username: tornado
The user name is: tornado
The user age is: 26
To be continued