zoukankan      html  css  js  c++  java
  • Cookie的写入,和读取

        public static void SetLoginGmameInfo(string  uid, string sid, string timestring, string sign)
            {
                //System.Web.HttpContext.Current.Session["GoGoPortalmemberSessionUserID"] = userID.ToString();
                //System.Web.HttpContext.Current.Session["GoGoPortalmemberSessionUserName"] = userName;
                //System.Web.HttpContext.Current.Session["GoGoPortalmemberSessionUserPWD"] = userPWD;
                //ClearLoginSession();
                /////上面是session方式。以下是cookie方式
                System.Web.HttpCookie membercookie = System.Web.HttpContext.Current.Request.Cookies["GoGoGameInfoCookie"];
                if (membercookie == null)
                {
                    membercookie = new System.Web.HttpCookie("GoGoGameInfoCookie");
                }
                //membercookie.Expires = DateTime.Now ;//默认是关闭浏览器就失效,不保存到磁盘
                membercookie.Values.Set("uid", uid.ToString());
                membercookie.Values.Set("sid", sid);
                membercookie.Values.Set("timestring", timestring);
                membercookie.Values.Set("sign", sign);
          
                //membercookie.Expires = DateTime.Now.AddHours(4);//设置cookie过期时间
                System.Web.HttpContext.Current.Response.SetCookie(membercookie);




            }

    上面的一个方法就是将uid,sid,timestring,string sign写入的cookie里面去了。cookie默认是关闭浏览器失效

    那我们改怎样使用这种方法呢SetLoginGmameInfo(uid, sid, time.ToString(), Sign);这样就写入了Cookie

    取出Cookie

    比方我要取出COOKIE里面我已经存入的UID


       /// <summary>
            /// 返回session的userid
            /// </summary>
            /// <returns></returns>
            public static string GetLoginUidCookie()
            {
               
                string Uid = "0";
                System.Web.HttpCookie membercookie = System.Web.HttpContext.Current.Request.Cookies["GoGoGameInfoCookie"];
                if (membercookie != null)
                {
                    Uid = membercookie["uid"].ToString();
                }
                return Uid;
            }



    然后定义一个变量string uid=GetLoginUidCookie();//就取出来Cookie了


  • 相关阅读:
    实用小软件
    没有找到MSVCP71.dll,迅雷5无法进行离线下载,P2P Seacher无法连入emule网络
    PSP2000V3版5.03系统误删PSP文件夹的拯救方案
    图书馆图书检索的小技巧
    thinkpad指点杆(trackpoint)在WPS的word文档中失效的解决办法
    笔记本电池死而复生
    调试Page.IsPostBack,感觉好奇怪
    OleDbSchemaGuid.Columns返回DataTable介绍
    静态类生命周期的问题
    IE中居中,FF中出问题
  • 原文地址:https://www.cnblogs.com/llguanli/p/6829296.html
Copyright © 2011-2022 走看看