Cookie application session
?
?
?
1.將信息寫入Cookies 中/
方式一
//HttpCookie hcName = new HttpCookie("UserName", this.txtName.Text);
//HttpCookie hcPwd = new HttpCookie("UserPwd", this.txtPassword.Text);
//hcName.Expires = DateTime.Now.AddDays(double.Parse(this.ddlDays.SelectedValue));
//hcPwd.Expires = DateTime.Now.AddDays(double.Parse(this.ddlDays.SelectedValue));
//this.Response.Cookies.Add(hcName);
//this.Response.Cookies.Add(hcPwd);
?
讀取
HttpCookie hcPwd = this.Request.Cookies["UserPwd"];
string s = "";
s = hcPwd.Value;
?
方式二
HttpCookie hc = new HttpCookie("User");
hc.Values.Add("name", this.txtName.Text.Trim());
hc.Values.Add("pwd", this.txtPassword.Text.Trim());
hc.Expires = DateTime.Now.AddDays(double.Parse(this.ddlDays.SelectedValue));
//將cookie對象寫入客戶端
this.Response.Cookies.Add(hc);
讀取
HttpCookie hc = this.Request.Cookies["User"];
string s = "";
if (hc != null)
{
s += "從Cookies中讀取的姓名是:" + hc.Values["name"].ToString() + "<br/>讀取的密碼是:" + hc.Values["pwd"].ToString();
}
else
{
s += "沒有Cookie對象!";
}
?
2 刪除cookie
?
總結
以上是生活随笔為你收集整理的Cookie application session的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 批量恢复文件的Py脚本
- 下一篇: 酷家乐砖缝怎么设置? 酷家乐配置砖缝的技