我在用户登录后设置一个Session和一个cookie,在检查某些条件时,用户被重定向到另一个页面,但是在page_load事件之后,Session和Cookie设置为NULL。 那是什么问题?
这是我的代码:
if (HttpContext.Current.Request.Cookies["LastSession"] != null)
HttpContext.Current.Response.Cookies.Remove("LastSession");
HttpCookie cookieLogSession = new HttpCookie("LastSession", strLogInID);
cookieLogSession.Expires = dtNow.AddDays(7);
//cookieLogSession.Path = "/";
HttpContext.Current.Response.Cookies.Add(cookieLogSession);
if (HttpContext.Current.Request.Cookies["Ad_LastSession"] != null)
HttpContext.Current.Response.Cookies.Remove("Ad_LastSession");
HttpCookie cookie = new HttpCookie("Ad_LastSession");
cookie.Value = (a variable);
//cookie.Path = "/";
cookie.Expires = dtNow.AddDays(7);
HttpContext.Current.Response.Cookies.Add(cookie);