标题:设计登录验证网页的问题
取消只看楼主
smilelake
Rank: 2
等 级:论坛游民
威 望:1
帖 子:31
专家分:30
注 册:2012-8-23
结帖率:0
已结贴  问题点数:2 回复次数:0 
设计登录验证网页的问题
设计登录验证网页的问题

环境:
VS 2010+SQL 05+WIN7 +IIS7

需求:
2个TextBox , 1个Button ,登录成功跳转success页面,否则跳转到Loginfailed页面;

问题:
点击Button 不跳转。请帮忙看看, 谢谢。

代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome2.aspx.cs"  %>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
<%@Import Namespace="System.Web"%>
<%@Import Namespace="System.Web.UI"%>
<%@Import Namespace="System.Web.Security"%>
<%@Import Namespace="System.Configuration"%>

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        string connString = "server=kevin-PC;uid=sa;pwd=1;database=SimpleVote";
        string user_input = this.TextBox1.Text.Trim();
        string Password_input = this.TextBox2.Text.Trim();
        
        SqlConnection conn = new SqlConnection(connString);
        conn.Open();
        SqlCommand cmd = conn.CreateCommand();
         = "select * from   UserInfo where UserID= ' " + user_input + " ' and Password= ' " + Password_input + " ' ";

        SqlDataReader reader=cmd.ExecuteReader();

        if (reader.Read()=true)
        {//通过身份验证
            
            Response.Redirect("./success.aspx");
            
            //将在线用户信息写入Session
            //Session["sessUserName "] = TextBox1.Text;
        }
        else
        {//未通过身份验证
           
            Response.Redirect("./Loginfailed.aspx");
        }

    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("./Loginfailed.aspx");
    }
</script>

<html>
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
   
    &nbsp;<br />
        <br />
 
   
    </div>
    </form>
</body>
</html>


[ 本帖最后由 smilelake 于 2012-8-24 00:11 编辑 ]
搜索更多相关主题的帖子: 设计 网页 success 
2012-08-23 20:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-380010-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053602 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved