ASP.NET Cookie

保存Cookie
以保存username 和userPhone为例子

            //保存Cookie 方法一
            Response.Cookies["username"].Expires = DateTime.Now.AddDays(1.0);
            Response.Cookies["username"].Value = this.txtCookie.Text;

            //保存Cookie 方法二
            HttpCookie cookie = new HttpCookie("userPhone","123456");
            cookie.Expires = DateTime.Now.AddDays(1.0);
            Response.Cookies.Add(cookie);

读取Cookie

            Response.Write($"username={Request.Cookies["username"].Value}  userPhone={Request.Cookies["userPhone"].Value}");
发布了239 篇原创文章 · 获赞 174 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/Maybe_ch/article/details/92441865