I want to end the cookie for FormsAuthentication when the browser is closed. (I want it to work, how the PHP session works)
Here is my Auth code which is in Model (Not controller).
Models / Auth.cs
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, model.UserId, DateTime.Now, DateTime.Now.AddDays(1), true, model.UserId +" "+reader["lastname"], FormsAuthentication.FormsCookiePath); string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } HttpContext.Current.Response.Cookies.Add(cookie);
Web.config
<authentication mode="Forms"> <forms name="user" timeout="60" loginUrl="~/Auth/login" path="/"></forms> </authentication> <authorization> <deny users="?" /> </authorization>
And one more question: is there a 2 time set cookie timeout,
on the ticket
DateTime.Now.AddDays(1),
and during authentication in the Web.config file
<forms name="user" timeout="60" loginUrl="~/Auth/login" path="/"></forms>
how different are they, and which one will affect the actual expire cookie?
Does anyone know please let me know.
Thanks!
Expert wanna be
source share