1. 猴子技术宅首页
  2. html干货教程

asp.net cookie的读写实例分享


代码如下:
HttpCookie cookie = new HttpCookie(“AutoLogin”);
cookie.Values.Add(“name”, user.UserName);
cookie.Values.Add(“pass”, user.Password);
cookie.Expires = DateTime.Now.AddDays(1);
Response.AppendCookie(cookie);
代码如下:
HttpCookie cookies = Request.Cookies[“AutoLogin”];
if (!IsPostBack)
{
if (cookies != null)
{
string name = cookies.Values[“name”];
string pass = cookies.Values[“pass”];
if (name != null && !name.Equals(“”) && pass != null && !pass.Equals(“”))
{
UserManager userManager = new UserManager();
if (userManager.Login(name, pass, out user))
{
limits = userManager.GetLimitsById(user.ID);
Session[“limits”] = limits;
Session[“CurrentUser”] = user;
Response.Redirect(“~/Display/Car/CarList.aspx”);
}
}
}
}

清空cookies
Response.Cookies[“AutoLogin”].Expires = DateTime.Now.AddDays(-1);

—-想了解更多的linux相关异常处理怎么解决关注<猴子技术宅>



本文来自网络收集,不代表猴子技术宅立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ssfiction.com/archives/74299

发表评论

电子邮件地址不会被公开。 必填项已用*标注