0

当我尝试使用用户名和密码登录另一个页面时,页面刷新时什么也没有发生。

<%@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 = "#page2"
  MM_redirectLoginFailed = "error.html"

  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 rel="stylesheet" href="themes/vtapp.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile.structure-1.3.2.min.css" />
<style type="text/css">
body,td,th {
    font-family: "Myriad Pro";
    font-size: 14px;
    color: #000;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>

<body>
<div data-role="page" id="page">
<div data-role="content" data-theme="a">
    <form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
      <table width="284" border="0" cellpadding="3" cellspacing="3">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Enter Username and Password</td>
        </tr>
        <tr>
          <td><input name="username" type="text" id="username" value="blay" /></td>
        </tr>
        <tr>
          <td><input name="password" type="text" id="password" value="BBBBBB" /></td>
        </tr>
        <tr>
          <td><div align="center">
            <input type="submit" name="button" id="button" value="  Sign In  " />
          </div></td>
        </tr>
      </table>
      <p>&nbsp;</p>
    </form>
    <div data-role="page" id="page2">
      <div data-role="header">
        <h1>Header</h1>
      </div>
      <div data-role="content">Welcome User</div>
    </div>
</div>
</div>
</body>
</html>

在检查所写的所有内容后,所有代码都是正确的,应该可以工作。

4

1 回答 1

0

Dreamweaver 产生了非常可怕的 ASP 代码。我能提供的最好建议是让您在谷歌上搜索有关如何在 Classic ASP 中编写登录表单的教程。这里有一个

http://www.w3schools.com/website/web_asp_login.asp

还有很多其他的。完成后,删除所有 Dreanweaver 生成的垃圾并用您自己的代码替换它。

无论如何,查看您页面中的 HTML,我看不到决定是显示登录表单还是显示欢迎消息的逻辑。尝试一些类似的东西

<% if Session("MM_UserAuthorization") = "" then %>
  <form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
     (rest of your form here, I'm not going to copy it all)
  </form>
<% else %>
  <div data-role="page" id="page2">
   <div data-role="header">
    <h1>Header</h1>
   </div>
   <div data-role="content">Welcome User</div>
  </div>
<% end if %>
于 2013-11-16T12:13:40.037 回答