StateServer Cookies问题
登录代码
if (!string.IsNullOrEmpty(AutoLogin)) {//添加cookies HttpCookie hc = new HttpCookie("userid"); hc.Value = CurrentMember.ID.ToString(); hc.Expires = DateTime.Now.AddDays(1000); context.Response.Cookies.Add(hc); } else {//移除cookies HttpCookie hc = new HttpCookie("userid"); hc.Expires = DateTime.Now.AddDays(-10000); context.Response.Cookies.Add(hc); }
HttpCookieCollection hcc = context.Request.Cookies; if (currentMember == null) { Log.write("session为空,检测Cookies值"); if (hcc["userid"] != null) { Log.write("cookies值不为空,值为" + hcc["userid"].Value); currentMember = ModelList.MemberList.Where(x => x.ID == hcc["userid"].Value.ToInt()).FirstOrDefault(); } }
<sessionStatemode="StateServer"stateConnectionString="tcpip=127.0.0.1:42424"sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"cookieless="false"timeout="20"/>