永发信息网

asp.net cookies问题,帮忙指点

答案:2  悬赏:10  手机版
解决时间 2021-07-25 15:08
  • 提问者网友:鼻尖触碰
  • 2021-07-25 04:42

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);

最佳答案
  • 五星知识达人网友:动情书生
  • 2021-07-25 05:58

string kk = Response.Cookies["userid"].value;



HttpCookie cook = new HttpCookie("userid",txtNam);
cook.Expires = DateTime.Today.AddDays(30);
Response.Cookies.Add(cook);

全部回答
  • 1楼网友:舍身薄凉客
  • 2021-07-25 06:13

我看代码没看出错误 但是我总感觉你那逻辑不对哦!

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯