Cookies 记不住信息是什么原因?
cs: private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["web"] != null)
{
this.textfield.Value = Request.Cookies["userid"].Value;
}
}
}
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
if (this.CheckBox1.Checked == true)
{
HttpCookie cookieinfo = new HttpCookie("web");
cookieinfo.Values.Clear();
cookieinfo["userid"] = this.textfield.Value.Trim();
cookieinfo.Expires = DateTime.Today.AddDays(30);
Response.Cookies.Add(cookieinfo);
}
}
断点跟踪后发现,首次登陆后确实执行了Button1_Click里的内容,但是二次登录后Request.Cookies["web"] 的值却 null,哪里出了问题?
[解决办法]
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="60"/>