关于cookies的详细用法——用户登录和注销(.NET版) 登录(记录Cookies用户名)
HttpCookie myCookie = new HttpCookie("userinfo");
myCookie["uname"] = txtName.Text.Trim();
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);
显示(用户名)
if (Request.Cookies["userinfo"] != null)
{
if (Request.Cookies["userinfo"]["uname"] != null)
{ userName.Text = Convert.ToString(Request.Cookies["userinfo"]["uname"]); }
}
删除Cookies
if (Request.Cookies["userinfo"] != null)
{
HttpCookie myCookie = new HttpCookie("userinfo");
myCookie["uname"] = null;
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。