N
news.microsoft.com
I am having a difficult time with cookies. In my code, I need to allow a user to login to my admin site. I figure I can set a cookie, then authenticate them, and all should be well. This works, however, when I want to log off the user, my cookie is giving my issues with the expiration date. The expiration date is always "1/1/1," so I cannot delete the cookie.
The code below is my login logic. When I login a user, I create them a cookie as persistant, then use FormsAuthentication.SetAuthCookie, then I redirect them to the main admin page. When I debug the code, I can see that the cookie does have a sensible expiration date, but after the Response.Redirect, the sensible expiration date becomes "1/1/1." This is killing me. Any thoughts?
Thanks.
HttpCookie cookie = new HttpCookie("MustSeeHomesAdmin");
cookie.Expires = System.DateTime.Now.AddDays(7);
cookie.Values["Persistent"] = "true";
cookie.Value = contact.UserPboID.ToString();
HttpContext.Current.Response.Cookies.Add(cookie);
// Authenticate the user
FormsAuthentication.SetAuthCookie( contact.UserPboID.ToString(),true);
// Redirect browser back to originating page
Response.Redirect( Request.UrlReferrer.AbsolutePath + "?mod=homes" );
The code below is my login logic. When I login a user, I create them a cookie as persistant, then use FormsAuthentication.SetAuthCookie, then I redirect them to the main admin page. When I debug the code, I can see that the cookie does have a sensible expiration date, but after the Response.Redirect, the sensible expiration date becomes "1/1/1." This is killing me. Any thoughts?
Thanks.
HttpCookie cookie = new HttpCookie("MustSeeHomesAdmin");
cookie.Expires = System.DateTime.Now.AddDays(7);
cookie.Values["Persistent"] = "true";
cookie.Value = contact.UserPboID.ToString();
HttpContext.Current.Response.Cookies.Add(cookie);
// Authenticate the user
FormsAuthentication.SetAuthCookie( contact.UserPboID.ToString(),true);
// Redirect browser back to originating page
Response.Redirect( Request.UrlReferrer.AbsolutePath + "?mod=homes" );