protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
Session["User"] = "Authenticated";
Session["Username"] = HttpContext.Current.User.Identity.Name;
Response.Redirect("HomePage.aspx");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (recordExistCount == 1)
{
Session["User"] = "Authenticated";
Session["Username"] = txtUsername.Text.Trim();
fc.IsOnlineRecord(Session["Username"].ToString(),true);
var ticket = new FormsAuthenticationTicket(2,Session["username"].ToString(),DateTime.Now,DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), true,"",FormsAuthentication.FormsCookiePath);
var encryptedTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
{
HttpOnly = FormsAuthentication.RequireSSL,
Path = FormsAuthentication.FormsCookiePath,
Domain = FormsAuthentication.CookieDomain
};
Response.Cookies.Add(cookie);
Response.Redirect("HomePage.aspx");
}
<authentication mode="Forms">
<forms loginUrl="LoginPage.aspx"
protection="All"
timeout="60"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="HomePage.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false"/>
</authentication>
My page times out when its left idle for more than 10 mins. I wonder what is going wrong?
It might be your session that is timing out, not the Form. Have you set the session timeout in the Web.Config? This can be done in the sessionState element (inside the system.web element)
Check this link for more info: http://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=VS.100%29.aspx