cookie

 

//1.Cookie为多值的情况:

        HttpCookie httpCookie = Page.Request.Cookies["LOGININFO"];

        httpCookie.Values["UserName"] = username;

        httpCookie.Values["DeptId"] = deptId;

        httpCookie.Values["Culture"] = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

        httpCookie.Expires = DateTime.Now.AddDays(8);

        Page.Response.Cookies.Set(httpCookie);//使用Set更新时,如果指定的key不存在,也会新增CookieCookie Collection

        Page.Response.Cookies.Add(httpCookie);//cookienull,Cookies.Add();

        //读取Cookie:string strValue1=Page.Request.Cookies["LOGININFO"].Values["RealName"];

        //2.Cookie为单值的情况:

        HttpCookie httpCookie = Page.Request.Cookies["LOGININFO"];

        httpCookie.Value = DateTime.Now.ToString();

        httpCookie.Expires = DateTime.Now.AddDays(8);

        Page.Response.Cookies.Add(httpCookie);

        //读取Cookie:string strValue=Page.Request.Cookies["LOGININFO"].value;

        //3.所有cookie的集合:

        System.Web.HttpCookieCollection reqcookie = Request.Cookies;//是获取所有的cookie

        System.Web.HttpCookieCollection reqcookie = Request.Cookies;

        System.Web.HttpCookieCollection respcookie = new HttpCookieCollection();

        for (int i = 0; i < reqcookie.Count; i++)

        {

            if (reqcookie[i].Name != "ASP.NET_SessionId")

            {

                System.Web.HttpCookie cookie = new HttpCookie(reqcookie[i].Name);

                cookie.Expires = DateTime.Now;

                respcookie.Add(cookie);    }

        }//移除ASP.NET_SessionIdcookie,(主要用于退出登录);

        //4. Response.Cookies["eVoucherLoginType"].Value = "Cert";//作用?

        Response.Cookies["eVoucherLoginType"].Expires = DateTime.Now.AddDays(15);

        //6.javascipt获取cookie

        function getcookie(name)

        {

            var arr=document.cookie.match(new regexp("(^|)"+name+"=([^;]*)(;|$)"));

            if(arr!=null) {

            return arr[2]; } return null;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值