设计登录验证网页的问题
设计登录验证网页的问题环境:
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" />
<br />
<br />
</div>
</form>
</body>
</html>
[ 本帖最后由 smilelake 于 2012-8-24 00:11 编辑 ]