首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

cookies 判断登入时间,该怎么解决

2012-04-13 
cookies 判断登入时间做个登入 用Cookie 记录时间,登入错误3 次后 冻结 等到3分钟后才能正常登入,这个cook

cookies 判断登入时间
做个登入 用Cookie 记录时间,登入错误3 次后 冻结 等到3分钟后才能正常登入,这个cookie 要怎么写啊11111111

[解决办法]

C# code
protected void btnSave_Click(object sender, EventArgs e){  HttpCookie cookie = Request.Cookies["UserID"];  if (cookie == null)  {    cookie = new HttpCookie("UserID", "0");    cookie.Expires = DateTime.Now.AddMinutes(3);        }  int i = Convert.ToInt16(cookie.Value);  if (i >= 3)  {    Response.Write("<script>window.alert('登入3次');</s" + "cript>");    return;  }  string connStr = "Data Source=.;Initial Catalog=SchoolDB;Integrated Security=True ";  string sql = "select count(UserID) from Student where UserName=@UserName And [PassWord]=@Password";  using (SqlConnection conn = new SqlConnection(connStr))  {    SqlCommand comm = new SqlCommand();    comm.Connection = conn;    comm.CommandText = sql;    comm.Parameters.AddWithValue("@UserName", this.txtUserNam.Text);    comm.Parameters.AddWithValue("@Password", this.txtPassWord.Text);    conn.Open();    SqlDataReader dr = comm.ExecuteReader();    if (dr.HasRows)    {      Response.Write("登入成功!");    }    else    {      i++;      cookie["UserID"] = i.ToString();    }  }  Response.Cookies.Add(cookie);} 

热点排行