I've got a cookie that I'm using to persist a user's userid but I'm having a hard time replacing it with a new value. According to MSDN, I should be able to simply overwrite the value, but it hasn't been working. I'm doing the login logic in a handler and passing the user on to a new webpage if they succeed.
public void ProcessRequest(HttpContext context)
{
User user = User.FindByUsernameAndPassword(
context.Request.Form["username"],
context.Request.Form["password"]);
context.Response.Cookies["user_id"].Value = user.ID.ToString();
context.Response.Redirect("/profile", true);
}
The first time I log in it works well, but if I try to overwrite my current cookie by hitting the handler with a new user id, it doesn't change the cookie value and I continue to be logged in as the user I was when I hit it.
Other pages use the cookie to log in, but because the user id isn't changing it doesn't change the logged in user.
public User User { get; set; }
public override void Page_Load()
{
this.User = User.Find(int.Parse(Request.Cookies["user_id"].Value));
}