标签:mem 模块 pre exp i++ 验证 color 验证码 code
一个比较完善的登录模块,就目前的知识范围来说应该算是完美的。
涉及到:cookies,Session,验证码等知识面
Cookies存放一组值:
HttpCookie cook = new HttpCookie("userCook"); cook.Values["name"] = this.TextBox1.Text; cook.Values["pwd"] = this.TextBox2.Text; cook.Expires = DateTime.Now.AddDays(3); Response.Cookies.Add(cook); Response.Redirect("AdminIndex.aspx");
取值:
if (!IsPostBack) { //已经登录过的,在Session有效期间可以免登录 if (Session["userInfo"] != null) { Response.Redirect(@"../Manage/AdminIndex.aspx"); }else if (Request.Cookies["userCook"] != null) { //回显登录用户的信息 this.TextBox1.Text = Request.Cookies["userCook"]["name"].ToString(); this.TextBox2.Text = Request.Cookies["userCook"]["pwd"].ToString(); } }
验证码忽略大小写
//忽略大小写 if (!Session["code"].ToString().Equals(this.TextBox3.Text, StringComparison.InvariantCultureIgnoreCase)) { Response.Write("<script>alert(‘验证码输入不正确‘)</script>"); return; }
验证码的产生
/// <summary> /// 生成验证码 /// </summary> /// <param name="length">指定验证码的长度</param> /// <returns></returns> public string CreateValidateCode(int length) { string strArr = "0123456789abcdefghijklmnopqrxyzABCDEFGHIJKLMNOPQRXYZ"; char[] charArr = strArr.ToCharArray(); Random r = new Random(); string validateNumberStr = null; for (int i = 0; i < length; i++) { int a1 = r.Next(0, charArr.Length); validateNumberStr = validateNumberStr + charArr[a1] + ""; } return validateNumberStr; }
其他的知识,数据库中查询主键不连续表中一定范围的数据(如:第20条到第30条的数据)
思路:给表中加一列标号,然后再用子查询
加一列,编号 select *,ROW_NUMBER() over(order by MemberID) as num from [dbo].[tb_Member]
子查询 select [Address],PostCode,LoadDate from (select *,ROW_NUMBER() over(order by MemberID) as num from [dbo].[tb_Member]) as t where num>=1 and num<=5
其他的后续再补充!!
标签:mem 模块 pre exp i++ 验证 color 验证码 code
原文地址:http://www.cnblogs.com/gx-143/p/6105326.html