或许我做错了,为什么在进行重定向时没有设置cookie?
static void doLogin()
{
var req = HttpContext.Current.Request;
...
user_cookie.set(userId, loginId);
...
HttpContext.Current.Response.Redirect(req["returnLocation"]);
}
static public void set(long userId, long loginId)
{
var cookies = HttpContext.Current.Request.Cookies;
var u = new HttpCookie("userId", userId.ToString());
u.HttpOnly = true;
var l = new HttpCookie("loginId", loginId.ToString());
l.HttpOnly = true;
cookies.Add(u);
cookies.Add(l);
}
答案 0 :(得分:4)
您正在向请求 .Cookies集合中添加Cookie,您需要将它们添加到响应 .Cookies集合中。
另请注意,Response.Redirect将中止当前我看到的导致问题的线程。 Response.Redirect(url,false)将重定向而不会中止。