I set an AuthCookie in Login Action Method like this
FormsAuthentication.SetAuthCookie(username,true);
and in the Global.asax file I put the refresh code, (this will be executed after each action method authentication)
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, true);
var ticket = FormsAuthentication.Decrypt(cookie.Value);
var newticket = new FormsAuthenticationTicket(ticket.Version,
ticket.Name,ticket.IssueDate,
ticket.Expiration,true,"new user data",ticket.CookiePath);
cookie.Value = FormsAuthentication.Encrypt(newticket);
cookie.Expires = newticket.Expiration.AddHours(24);
HttpContext.Current.Response.Cookies.Set(cookie);
}
But it's not working and it log out after a small period of time, although when I check that cookie with through browser settings, the expiration time was set correctly.