• cookie


    //添加Cookie
                //第一种添加Cookie方法
                HttpCookie myCookie = new HttpCookie("userrole");
                myCookie.Values["a"] = "a";
                myCookie.Values["b"] = "b";
                myCookie.Expires.AddDays(1);
                Response.AppendCookie(myCookie);
              
                //第二种添加Cookie方法
                HttpCookie myCookie = new HttpCookie("userrole");
                myCookie.Values["a"] = "a";
                myCookie.Values["b"] = "b";
                myCookie.Expires.AddDays(1);
                Response.Cookies.Add(myCookie);
    
                //第三种添加Cookie方法
                HttpCookie myCookie = new HttpCookie("userrole");
                myCookie.Value = "a";
                Response.Cookies.Add(myCookie);
    
                //第四种添加Cookie方法
                HttpContext.Current.Response.Cookies.Add(new HttpCookie("userrole", "超级管理员"));
                Response.Cookies["userrole"].Value = "超级管理员";
                HttpCookie cookie = Request.Cookies["userrole"];
                Response.Write(cookie.Value);
    
                //第五种添加Cookie方法
                string strName = "a";
                string strValue = "b";
                int  expires = 2;
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
                if (cookie == null)
                {
                    cookie = new HttpCookie(strName);
                }
                cookie.Value = strValue;
                cookie.Expires = DateTime.Now.AddMinutes(expires);//可以不写
                HttpContext.Current.Response.AppendCookie(cookie);
    
                //第六种添加Cookie方法
                string strName = "a";
                string strValue = "b";
                string key = "c";
              
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
                if (cookie == null)
                {
                    cookie = new HttpCookie(strName);
                }
                cookie[key] = strValue;
                cookie.Expires = DateTime.Now.AddMinutes(expires);
                HttpContext.Current.Response.AppendCookie(cookie);
    
                
             
                //获取cookie
                //第一种获取Cookie方法
                Response.Write(Request.Cookies["userrole"].Values["a"].ToString());
    
                //第二种读取Cookie方法
                HttpCookie cookie = Request.Cookies["userrole"];
                Response.Write(cookie.Values["a"].ToString());
                Response.Write(cookie.Values["b"].ToString());
             
               
                //第三种读取Cookie方法
                Response.Write(Request.Cookies["userrole"].Value);
             
                //第四种读取Cookie方法
                Response.Write(Request.Cookies["userrole"].Value);
    
                //第五种读取Cookie方法
               if( HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
                    HttpContext.Current.Request.Cookies[strName].Value.ToString();
               //第六种读取Cookie方法
               if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null && HttpContext.Current.Request.Cookies[strName][key] != null)
                   HttpContext.Current.Request.Cookies[strName][key].ToString();
    Cookie
  • 相关阅读:
    bzoj 2038 [2009国家集训队]小Z的袜子(hose)
    【NOIP2014模拟11.1B组】吴传之火烧连营
    【NOIP2014模拟11.1B组】蜀传之单刀赴会
    phpmystudy:mysql启动失败
    英文漏洞报告解读(一)——PHP 5.4.x < 5.4.32 Multiple Vulnerabilities
    brupsuit Compare 模块及其应用场景
    Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
    android ViewPager实现的轮播图广告自定义视图,网络获取图片和数据
    Android首页轮播图直接拿来用
    java 调用webservice的各种方法总结
  • 原文地址:https://www.cnblogs.com/zhubenxi/p/5199876.html
Copyright © 2020-2023  润新知