Sub-class entry and proficient series of ASP components

xiaoxiao2021-03-06  47

Let's learn to look at the Response object. In fact, the Write method of this object has been used in our previous tutorial.

Here we use the Response object to set cookies.

?

Open VB6, create a new ActiveX DLL project. The engineering name is modified to FCOM and the class name is modified to FZ5 reference "Microsoft Active Server Pages Object" object library. Create two component events: OnStartPage and OneundPage Create a reference to the class ScriptingContent in the event onstartpage. Instantiated class scriptingcontent.

?

code show as below:

Option expedition

'Statement of the object

DIM MyResponse as response

DIM MyRequest as Request

DIM MyApplication AS Application

DIM MyServer As Server

DIM MySession as session

?

??? 'When the component is created, it will trigger this event.

Public Sub onstartPage (MyScriptingContent as scriptingcontext)

???? 'Installation of objects

???? set myresponse = myscriptingContent.response

???? set myRequest = myscriptingContent.request

???? set myserver = myscriptingcontent.server

???? set myapplication = myscriptingContent.Application

???? set myations = myscriptingContent.Session

End Sub

?

??? 'When the component is destroyed, it triggers this event.

Public Sub OneendPage ()

???? 'destroyed object

???? set myresponse = Nothing

???? set myRequest = Nothing

???? set myServer = Nothing

???? set myapplication = Nothing

???? set mysession = Nothing

End Sub

?

'Set up cookies from the page, get it in the component

Public Sub getCookie ()

??? DIM MyItem

??? 'full 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 is" & ":" & myRequest.cookies ("agn")

??? myresponse.write ""

End Sub

Set cookies in the component, get it in the page

Public SUB setCookie ()

??? myresponse.cookies ("com_username") = "Tornado" ??? MyResponse.cookies ("com_age") = 26

??? myresponse.expires = # 9/13/2004 #

End Sub

?

Compiled into a DLL file, the system will automatically register.

Otherwise, register with regr32 f: /test/fcom.dll

?

test

Open Visual InterDev6.0 to generate a FZ5.asp file

<% @ Language = VBScript%>

<%

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 up in the page

Response.cookies ("UserName") = "Tornado"

Response.cookies ("age") = 26

Call obj.getcookie ()

?

%>

?

Configure a virtual directory, perform FC5.asp files in IE, you can see

Tornado 26age: 26Username: Tornado COM_AGE: 26COM_USERNAME: Tornado Among them, the tornado is: 26

Last continued

转载请注明原文地址:https://www.9cbs.com/read-117380.html

New Post(0)