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了


  • 相关阅读:
    [ZJOI2007]时态同步 题解
    Xposed 在android 6.0上报couldn't load class,找不到xposed_init中配置的入口类
    微信小程序http 400问题
    在Mac上 python中使用tesseract OCR (Pytesser) 识别图片中的文字
    微信小游戏跳一跳简单手动外挂(基于adb 和 python)
    第一个微信小程序踩的几个小坑
    android studio/Intellij IDEA(MAC OSX)中android模拟器无法启动的一种原因
    【转载】word2vec原理推导与代码分析
    HTTP Get Post究竟有哪些区别
    初试kotlin:用Kotlin开发桌面/CommandLine 工具
  • 原文地址:https://www.cnblogs.com/llguanli/p/6829296.html
Copyright © 2011-2022 走看看