用户使用JQUERY和ASP登录

时间:2013-10-03 09:30:57

标签: asp-classic

我有这个用asp经典设计的jquery移动页面。当我测试并尝试登录时,它会再次将我反弹回登录页面,而不是将我带到经过身份验证的用户的索引页面。这是我的代码:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/VT.asp" -->
<%
    ' *** Validate request to log in to this site.
    MM_LoginAction = Request.ServerVariables("URL")
    If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
    MM_valUsername = CStr(Request.Form("username"))
    If MM_valUsername <> "" Then
        Dim MM_fldUserAuthorization
        Dim MM_redirectLoginSuccess
        Dim MM_redirectLoginFailed
        Dim MM_loginSQL
        Dim MM_rsUser
        Dim MM_rsUser_cmd

        MM_fldUserAuthorization = ""
        MM_redirectLoginSuccess = "source.asp"
        MM_redirectLoginFailed = "error.asp"

        MM_loginSQL = "SELECT Username, Password"
        If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
        MM_loginSQL = MM_loginSQL & " FROM dbo.Test_Register_Users WHERE Username = ? AND Password = ?"
        Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
        MM_rsUser_cmd.ActiveConnection = MM_VT_STRING
        MM_rsUser_cmd.CommandText = MM_loginSQL
        MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 70, MM_valUsername) ' adVarChar
        MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 50, Request.Form("password")) ' adVarChar
        MM_rsUser_cmd.Prepared = true
        Set MM_rsUser = MM_rsUser_cmd.Execute

        If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
            ' username and password match - this is a valid user
            Session("MM_Username") = MM_valUsername
            If (MM_fldUserAuthorization <> "") Then
                Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
            Else
                Session("MM_UserAuthorization") = ""
            End If
            if CStr(Request.QueryString("accessdenied")) <> "" And true Then
                MM_redirectLoginSuccess = Request.QueryString("accessdenied")
            End If
            MM_rsUser.Close
            Response.Redirect(MM_redirectLoginSuccess)
        End If
        MM_rsUser.Close
        Response.Redirect(MM_redirectLoginFailed)
    End If
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>
</head>

<body>
<div data-role="page" id="page">
  <div data-role="header">
    <h1>Header</h1>
  </div>
  <div data-role="content">
    <form id="form1" name="form1" method="POST" action="login_code.asp">
      <table width="325" border="0" cellpadding="3" cellspacing="3">
        <tr>
          <td width="94">&nbsp;</td>
          <td width="210">&nbsp;</td>
        </tr>
        <tr>
          <td>Username</td>
          <td><input type="text" name="username" id="username" /></td>
        </tr>
        <tr>
          <td>Password</td>
          <td><input type="text" name="password" id="password" /></td>
        </tr>
        <tr>
          <td colspan="2"><div align="center">
            <input type="submit" name="button" id="button" value="Submit" />
          </div></td>
        </tr>
      </table>
    </form>
  </div>
  <div data-role="footer">
    <h4>Footer</h4>
  </div>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

如果您要连接到SQL数据库我不相信?对于参数是正确的,您应该将它们更改为@Username@Password,然后更改以下内容行:

MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("Username", 200, 1, 70, MM_valUsername) ' adVarChar
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("Password", 200, 1, 50, Request.Form("password")) ' adVarChar

我看不到你的代码有任何其他问题,但我对Classic ASP不是很好,所以我可能错了。尝试添加日志记录步骤,以查看代码执行的位置与您认为应该在哪里相比