Persisitent authentication
-
I'm using forms authentication on my site, and I want the login to be persistent (saved in a cookie?) for a number of days so that the user doesn't have to login each time he visits. Here's the code I use on my login page:
if (membership.ValidateUser(this.username.Text, this.password.Text))
{
FormsAuthentication.Initialize();
DateTime dtNow = DateTime.Now;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.username.Text, dtNow, dtNow.AddMinutes(30), true, "user", FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
Response.Redirect(FormsAuthentication.GetRedirectUrl(this.username.Text, true));
}What am I doing wrong (or what am I missing)?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
I'm using forms authentication on my site, and I want the login to be persistent (saved in a cookie?) for a number of days so that the user doesn't have to login each time he visits. Here's the code I use on my login page:
if (membership.ValidateUser(this.username.Text, this.password.Text))
{
FormsAuthentication.Initialize();
DateTime dtNow = DateTime.Now;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.username.Text, dtNow, dtNow.AddMinutes(30), true, "user", FormsAuthentication.FormsCookiePath);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
Response.Redirect(FormsAuthentication.GetRedirectUrl(this.username.Text, true));
}What am I doing wrong (or what am I missing)?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001This may help: http://blogs.msdn.com/tmeston/archive/2003/07/24/10505.aspx[^]