Cookie读写

config



"UserCookie" value="UserName"/>

.cs

//读取判断cookie为空为cookie赋一个值

protected void Page_Load(object sender, EventArgs e)
{

        string cookieName = System.Configuration.ConfigurationManager.AppSettings["UserName"];

if (Request.Cookies[cookieName] == null)
             {
                 HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
                 if (cookie == null)
                 {
                     cookie = new HttpCookie(cookieName);
                 }
                 cookie.Value = "111111";
                 cookie.Expires = DateTime.MaxValue;
                 Response.SetCookie(cookie);
             }
      return Request.Cookies[cookieName].Value;
}

 

转载于:https://www.cnblogs.com/JarvisNote/p/5046998.html

你可能感兴趣的:(Cookie读写)