【问题标题】:how to create form validation in classic asp?如何在经典 asp 中创建表单验证?
【发布时间】:2015-02-13 17:54:38
【问题描述】:

我是经典asp的新手。我创建了简单的登录表单,其中仅包含用户名和密码。

这是我的 logon.asp:

<%
Username="Administrator"
Password="Admin"
Validated = "OK"
if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
'Set the validation cookie and redirect the user to the original page.
    Response.Cookies("ValidUser") = Validated
    'Check where the users are coming from within the application.
    If (Request.QueryString("from")<>"") then
    Response.Redirect Request.QueryString("from")
    else
    'If the first page that the user accessed is the Logon page,
        'direct them to the default page.
          Response.Redirect "MyPage.asp"
    End if    
Else
' Only present the failure message if the user typed in something.
    If Request.Form("User") <> "" then
        Response.Write "<h3>Authorization Failed.</h3>" & "<br>" & _
        "Please try again.<br>&#xa0;<br>"
    End if
End if
%>
</head>
<body bgcolor="#FFFFFF">
<FORM ACTION=<%Response.Write "Logon.asp?"&Request.QueryString%> method="post">
<p> 
Username: 
<INPUT TYPE="text" NAME="User" VALUE='' size="20"></INPUT> <br />
Password: 
<INPUT TYPE="password" NAME="password" VALUE='' size="20"></INPUT>
<INPUT TYPE="submit" VALUE="Logon"></INPUT>
</FORM>

这是我的页面.asp:

<%
Validated = "OK"
if Request.Cookies("ValidUser") <> Validated then
'Construct the URL for the current page.
    dim s
    s = "http://"
    s = s & Request.ServerVariables("HTTP_HOST")
    s = s & Request.ServerVariables("URL")
    if Request.QueryString.Count > 0 THEN
    s = s & "?" & Request.QueryString 
    end if
    'Redirect unauthorized users to the logon page.
    Response.Redirect "Logon.asp?from=" &Server.URLEncode(s)
End if
%>
<html>
<head>
<title>My Protected Page</title>
</head>
<body>
<p align="center">This is my secret information<br>
You cannot see it unless you<br>
are properly logged on!</p>

当我在未填写输入字段的情况下输入登录按钮时,它会显示为“需要用户名或密码”。请问,如何创建验证码,以及如何在我现有的代码中添加代码?

任何asp专家都可以指导我,在此先感谢。

【问题讨论】:

    标签: validation asp-classic


    【解决方案1】:

    请在您的 logon.asp 页面中再添加一个条件:

        <%
        Username="Administrator"
        Password="Admin"
        Validated = "OK"
    If Trim(Request.Form("User")) <> "" And Trim(Request.Form("password")) <> "" Then
        if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
        'Set the validation cookie and redirect the user to the original page.
            Response.Cookies("ValidUser") = Validated
            'Check where the users are coming from within the application.
            If (Request.QueryString("from")<>"") then
            Response.Redirect Request.QueryString("from")
            else
            'If the first page that the user accessed is the Logon page,
                'direct them to the default page.
                  Response.Redirect "MyPage.asp"
            End if    
        Else
        ' Only present the failure message if the user typed in something.
            If Request.Form("User") <> "" then
                Response.Write "<h3>Authorization Failed.</h3>" & "<br>" & _
                "Please try again.<br>&#xa0;<br>"
            End if
        End if
    End If
        %>
        </head>
        <body bgcolor="#FFFFFF">
        <FORM ACTION=<%Response.Write "Logon.asp?"&Request.QueryString%> method="post">
        <p> 
        Username: 
        <INPUT TYPE="text" NAME="User" VALUE='' size="20"></INPUT> <br />
        Password: 
        <INPUT TYPE="password" NAME="password" VALUE='' size="20"></INPUT>
        <INPUT TYPE="submit" VALUE="Logon"></INPUT>
        </FORM>
    

    希望这会有所帮助。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 2011-09-12
      相关资源
      最近更新 更多