if (Response.Cookies["userid"] != null)
{
//string tt = Request.Cookies["userName"].ToString();
// Session["userName"] = Response.Cookies["UserName"].Value;
string kk = Response.Cookies["userid"].ToString();
Label1.Text = "值不为空";
}
else
{
Label1.Text = "值为空";
if (Request.Form["mylogo"] != null)
{
string txtName = null;
string txtPwd = null;
txtName = Request.Form["txtName"].ToString();
txtPwd = Request.Form["txtPwd"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["sqlConn"].ToString());
conn.Open();
string strsql = "select * from adminUser where Name='" + txtName + "' and pwe='" + MD5(txtPwd, 16) + "'";
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
//Session
Session["userName"] = txtName;
Session["userId"] = dt.Rows[0]["id"].ToString();
//cookies
HttpCookie cook = new HttpCookie("userid",txtNam);
Response.Cookies["userid"].Expires = DateTime.Today.AddDays(30);
Response.Cookies.Add(cook);
Label1.Text = "提交页面";
}
else
{
Response.Write("<script language=javascript>alert('用户名或密码错误!');</script>");
}
}
}
全部代码
这个保存时不是有错误。。
HttpCookie cook = new HttpCookie("userid",txtNam);
Response.Cookies["userid"].Expires = DateTime.Today.AddDays(30);
Response.Cookies.Add(cook);