C#做个登陆器,带验证码,求大家给个思路 应该是验证码和登录页没有关联起来。你应该先访问登陆页,带上CookieContainer,得到cookie后,再访问你验证码页面(带上得到的cookie),这样得到的验证码图片才是正确的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用fiddler调试下,看看你的提交和浏览器的有什么不同。 C#带验证码登陆示例<asp:TextBox ID="txtUid" runat="server" Font-Size="9pt" Width="120px" BackColor="White"></asp:TextBox>//登陆用户名<asp:TextBox ID="txtPwd" runat="server" Font-Size="9pt" TextMode="Password" Width="120px" style="margin-left: 0px" BackColor="White"> </asp:TextBox>//登陆密码<asp:TextBox ID="txtVali" runat="server" Font-Size="9pt" Width="60px" BackColor="White"></asp:TextBox>//验证码输入框<img id="Img1" align="left" alt="看不清,请点击我!" onclick="this.src=this.src+'?'" src="../youyu/CheckCode.aspx" style="width: 49px; height: 22px" />//验证码显示<asp:ImageButton ID="ImageManage" runat="server" ImageUrl="~/image/b1.jpg" OnClick="btnLoad_Click"/>//登陆事件//登陆事件处理验证protected void btnLoad_Click(object sender, ImageClickEventArgs e) { HttpCookie cookie = Request.Cookies["CheckCode"]; if (String.Compare(cookie.Value, txtVali.Text, true) != 0) { Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>"); } else { DataSet ds = DB.reDs("select * from tb_HuenLian where UserName='" + txtUid.Text.Trim() + "' and PassWord='" + txtPwd.Text.Trim() + "'"); int i = this.checkLogin(txtUid.Text, txtPwd.Text); if (i > 0) { Session["id"] = ds.Tables[0].Rows[0][0].ToString(); Session["UserName"] = this.txtUid.Text; Session["PassWord"] = this.txtPwd.Text; Page.Response.Redirect("Yonghu.aspx"); } else { Response.Write("<script lanuage=javascript>alert('用户名称或密码错误!');location='javascript:history.go(-1)'</script>"); } } } public int checkLogin(string loginName, string loginPwd) { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conn"]); SqlCommand myCommand = new SqlCommand("select count(*) from tb_HuenLian where UserName=@loginName and PassWord=@loginPwd", con); myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.NVarChar, 20)); myCommand.Parameters["@loginName"].Value = loginName; myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.NVarChar, 50)); myCommand.Parameters["@loginPwd"].Value = loginPwd; myCommand.Connection.Open(); int i = (int)myCommand.ExecuteScalar(); myCommand.Connection.Close(); return i; } C#累加异或值如何得到校验值。 用C#抓取网页的问题 软件开发分层时的问题 如何获得另一个窗体的textBox中的字符串? 关于C#将16进制转换成ASCii问题 高手进来看下。分布式软件 如何计算C#的代码量 解密之后信息带有乱字符,问题在哪里? 请教:如何获得当前项目所在目录? 网络短信息如何做 求一组数的连续的数的个数??? 请教C# reportViewer报表的矩表的问题
<asp:TextBox ID="txtUid" runat="server" Font-Size="9pt" Width="120px"
BackColor="White"></asp:TextBox>//登陆用户名
<asp:TextBox ID="txtPwd" runat="server" Font-Size="9pt" TextMode="Password"
Width="120px" style="margin-left: 0px" BackColor="White">
</asp:TextBox>//登陆密码
<asp:TextBox ID="txtVali" runat="server" Font-Size="9pt" Width="60px"
BackColor="White"></asp:TextBox>//验证码输入框
<img id="Img1" align="left" alt="看不清,请点击我!" onclick="this.src=this.src+'?'"
src="../youyu/CheckCode.aspx" style="width: 49px; height: 22px" />//验证码显示
<asp:ImageButton ID="ImageManage" runat="server" ImageUrl="~/image/b1.jpg"
OnClick="btnLoad_Click"/>//登陆事件
//登陆事件处理验证
protected void btnLoad_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies["CheckCode"];
if (String.Compare(cookie.Value, txtVali.Text, true) != 0)
{ Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
} else
{
DataSet ds = DB.reDs("select * from tb_HuenLian where UserName='" + txtUid.Text.Trim() + "' and PassWord='" + txtPwd.Text.Trim() + "'");
int i = this.checkLogin(txtUid.Text, txtPwd.Text);
if (i > 0)
{
Session["id"] = ds.Tables[0].Rows[0][0].ToString();
Session["UserName"] = this.txtUid.Text;
Session["PassWord"] = this.txtPwd.Text;
Page.Response.Redirect("Yonghu.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
}
}
}
public int checkLogin(string loginName, string loginPwd)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conn"]);
SqlCommand myCommand = new SqlCommand("select count(*) from tb_HuenLian where UserName=@loginName and PassWord=@loginPwd", con);
myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.NVarChar, 20));
myCommand.Parameters["@loginName"].Value = loginName;
myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.NVarChar, 50));
myCommand.Parameters["@loginPwd"].Value = loginPwd;
myCommand.Connection.Open();
int i = (int)myCommand.ExecuteScalar();
myCommand.Connection.Close();
return i;
}