1 ValidateCode.ashx 验证码文件,这是一个文件。。我想给大家上传上。。。但是没找到上传在哪。。。
2 Session["CheckCode"] 这个。。不懂神马意思。。
3 1.创建一个用户控件
4 用户名:TextBox
5 密码: TextBox
6 验证码:TextBox 验证码图片
7
8 <p>
9 验证码:<asp:TextBox ID="txt" runat="server"></asp:TextBox>
10 <img alt="验证码" src="/ValidateCode.ashx" title="看不清,换一张" onclick="Changeimg(this)" style="cursor:pointer" />
11
12 <script type="text/javascript"> //换图片的单机事件
13 function Changeimg(img) {
14 img.src = "ValidateCode.ashx?id=" + new Date();
15 }
16 </script>
17 </p>
18 2.因为用户控件不允许直接用URL访问,所以把用户控件拖到aspx上面
19 btnSubmit 单击事件
20
21 protected void btnSubmit_Click(object sender, EventArgs e)
22 {
23 if (!string.IsNullOrEmpty(txtVerify.Text.Trim())) //如果不为空
24 {
25 if (Session["CheckCode"].ToString().ToLower().Equals(txtVerify.Text.Trim())) //验证码与文本框比较是否相等
26 {
27 //Response.Write("<script>alert('验证成功')</script>");
28 string _user = txtUser.Text.Trim();
29 string _pwd = txtPwd.Text.Trim();
30 string sql = string.Format("SELECT * FROM TREE WHERE City='{0}' AND ID='{1}'",_user,_pwd);
31 int result = new BStudentInfo().GetSutdentInfo(sql);//数据库查询
32 if (result > 0)
33 {
34 Response.Redirect("TreeView.aspx"); //数据库验证和验证码输入正确之后跳转到"TreeView.aspx"页面
35 }
36 }
37 else
38 {
39 Response.Write("<script>alert('登录失败')</script>");
40 }
41 }
42
43 }
我感觉学的可迷糊了。。有时候都觉得在背代码。。。。哎。。好好加油~~
世界晚安