字典对象丢失其内容经典ASP

时间:2014-01-21 16:03:55

标签: object vbscript asp-classic session-variables

<%@ language = "VBScript"%>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
Username:<br> <input type = "text" name = "user"/><br>
Password:<br> <input type = "password" name = "pass"/><br>
<input type = "submit" name = "register_button" value = "Register"/>
<input type = "submit" name = "submit_button" value = "Submit"/>
</form> 

<%
set credentials = Server.CreateObject("Scripting.Dictionary")
set Session("credentials") = credentials 

if Request.form("register_button") <> "" then
    dim user
    dim pass
    pass = Request.form("pass")
    user = Request.form("user")

    Session("credentials").Add user, pass   
end if

if Request.form("submit_button") <> "" then 
    dim userd
    dim passd
    passd = Request.form("pass")
    userd = Request.form("user")
    if Session("credentials").Exists(userd) = true then
        if Session("credentials").Item(userd) = passd then
            Response.Write("ACCESS GRANTED")
        else 
            Response.Write("ACCESS DENIED")
        end if
    else
        Response.Write("USERNAME DOES NOT EXIST")
    end if
end if
%>

</body>
</html>

所以这是我使用Classic ASP创建的基本登录页面。当我输入用户并通过,然后单击注册,它将用户名和密码存储在字典中没有问题。但是,当我单击提交按钮(填写注册的凭据后),不知何故,字典的内容将被删除。因此,它失败了“if Session(”凭证“)。存在(userd)= true然后”语句。我甚至尝试将“凭证”作为普通变量,而不使用Session。它仍然无法正常工作,字典的内容会被删除。我怎样才能克服这个问题?提前谢谢!

1 个答案:

答案 0 :(得分:0)

第一个 凭据。添加用户并通过

set Session(“ credentials”)=凭据
应该在

之后