先是用户登陆,将用户信息用guid对应存储再session中
var dsfs = Guid.NewGuid().ToString();
HttpContext.Current.Session[dsfs] = ss;
然后将数据返回到客户端,客户端存储在cookie中
function setCookie(cname, cvalue, exdays) {
var d = new Date();
// d.setTime(d.getTime() + (exdays*1000));//设置过期时间是多少天后;
// d.setTime(d.getTime() + (exdays*60*60*1000));//设置过期时间是多少小时;
d.setTime(d.getTime() + (exdays * 60 * 60 * 1000));//设置过期时间是多少小时;
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
setCookie("sessionid", result.userid, 2);
然后用户客户端提交请求的时候都会带上cookie,然后这样获取(weapi)
var cookie = HttpContext.Current.Request.Cookies["sessionid"];
var session = HttpContext.Current.Session[cookie.Value];
mvc的话是这样
var cookie = HttpContext.Current.Request.Cookies["sessionid"];
usermessage session = HttpContext.Current.Session[cookie.Value] as usermessage;