ASP Components Intermediate beginner and proficient series of five

Source: Internet
Author: User
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











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.