实际上在我的asp.net应用程序中使用FormAuthentication Cookie,并将authenticationCookie设置为30天,但在IIS Forms Authentication设置中默认为30分钟。
我的问题是哪个超时首先到期?实际上我需要很长时间的身份验证Cookie到期。
这是我用来设置authenticationCookie超时的代码。
if (UserValidation(tbuser.Text, tbpass.Text))
{
Response.Cookies.Clear();
DateTime expiryDate = DateTime.Now.AddDays(30);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, tbuser.Text, DateTime.Now, expiryDate, true, String.Empty);
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
authenticationCookie.Expires = ticket.Expiration;
Response.Cookies.Add(authenticationCookie);
//FormsAuthentication.RedirectFromLoginPage(tbuser.Text, false);
Response.Redirect("Home.aspx");
}
答案 0 :(得分:2)
Cookie将根据您应用中的设置过期 - 即30天。
如果您没有在应用程序的web.config或代码中指定任何内容,那么您将继承默认值,但这不是这种情况。