I've implemented the Login button as following:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(u.UserID.ToString(), true, 2880);
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
cookie.Expires = DateTime.Now.AddMinutes(2880);
Response.Cookies.Add(cookie);
Response.Redirect("/index.aspx");
And this is my web config:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="Index.aspx" slidingExpiration="true" timeout="2880" />
</authentication>
My question is: when I deploy my web application to the hosting, once I'm logged in, I scrool around few pages in users directory, and almost immediately after 30 secs - 1 min I get logged out and redirected to the login page so that I can relog again. Why is this happening ??? I've tested it on my local machine and it works just fine?!?!
Can someone help me out with this ??
Are you hosting on a web farm?
If so, you are logging into one server and when you are redirected to a different server it can't decrypt your authentication ticket. All of the machine keys have to be the same across each of your web servers. See How To: Configure MachineKey in ASP.NET 2.0