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了
版权声明:本文为博主原创文章,未经博主允许不得转载。