〈 HTML 〉
〈 HEAD 〉〈 TITLE 〉Reading the Cookie Collection〈 /TITLE 〉〈 /HEAD 〉
〈 BODY 〉
〈 B 〉The contents of your Cookies are:〈 /B 〉〈 P 〉
〈 TABLE CELLPADDING=0 CELLSPACING=0 〉
〈 %
For Each Item in Request.Cookies
If Request.Cookies(Item).HasKeys Then
use another For...Each to iterate this collection
For Each ItemKey in Request.Cookies(Item)
Response.Write Item & "(" & ItemKey & ") = " _
& Request.Cookies(Item)(ItemKey) & "〈 BR 〉"
Next
Else
print the complete cookie string as normal
Response.Write Item & "=" & Request.Cookies(Item) & "〈 BR 〉"
End If
Next
% 〉〈 /TABLE 〉
〈 /BODY 〉
〈 /HTML 〉
...
If (Request.Cookies("User")("v1") 〈 〉 "alexhomer") _
Or (Request.Cookies("User")("v2") 〈 〉 "secret") Then
Response.Redirect "default.asp?nogood=yes&v1=" & Request.Cookies("User")("v1")
End If
...
...
Session("UserName") = Request("v1") username from logon dialog form
Session("Password") = Request("v2") password from logon dialog form
...
然后,当需要认证访问者时,就找到这些cookie并从中取回用户名和口令:
...
If (Session("UserName") 〈 〉 "alexhomer") _
Or (Session("Password") 〈 〉 "secret") Then
Response.Redirect "default.asp?nogood=yes&v1=" & Session("UserName")
End If
...
CREATE PROCEDURE AddUser @s_user varchar(12), @s_pword varchar (12) AS
IF EXISTS (SELECT * FROM Users WHERE sUserName = @s_user)
SELECT
ELSE
BEGIN
INSERT INTO Users (sUserName, sPassword)
VALUES(@s_user, @s_pword)
SELECT sUserName FROM Users WHERE sUsername = @s_user
END
Set oCon = Server.CreateObject("ADODB.Connection")
oCon.Open strConnect
建立command对象,设置属性
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = oCon our open connection
oCmd.CommandType = 4 its a stored procedure
oCmd.CommandText = "AddUser" the procedure name
提供参数执行command对象,得到结果:
Set oRs = oCmd.Execute (lngRecsAffected, Array(strUserName,strPassword))
strResult = Trim(oRs.Fields(0)) ADO may add a space to the result
显示结果,如果错误,显示“user exists warning”:
If strResult = "" Then
Response.Write "User Already Exists"
Else
Response.Write "Added new user: 〈 B 〉" & strResult & "〈 /B 〉"
End If
% 〉
...