持久化cookie不持久化
本文关键字:持久化 不持久 cookie | 更新日期: 2023-09-27 18:10:58
我创建了一个cookie:
FormsAuthentication.SetAuthCookie(e.EmployeID.ToString(), true);
我希望在明确退出之前保持登录状态,但在30分钟左右后,我必须重新登录。
这是我的第一个类:
public static class Authorization
{
public static bool Login(string username, string password, bool persist)
{
Employee e = ResourceManager.GetEmployeeByEmail(username);
if (e == null || !ResourceManager.VerifyEmployeePassword(e.EmployeID, password))
{
return false;
}
FormsAuthentication.SetAuthCookie(e.EmployeID.ToString(), persist);
return true;
}
public static void Logout()
{
FormsAuthentication.SignOut();
}
public static string GetUserId()
{
return HttpContext.Current.User.Identity.Name;
}
public static string GetUsername()
{
return GetEmployee().EmployeEmail;
}
public static bool IsAuthenticated()
{
return HttpContext.Current.User.Identity.IsAuthenticated;
}
public static Employee GetEmployee()
{
int id = 0;
int.TryParse(GetUserId(), out id);
return ResourceManager.GetEmployee(id);
}
public static bool IsAdministrator()
{
if (!IsAuthenticated())
{
return false;
}
Employee e = GetEmployee();
if (e != null)
{
return SecurityManager.IsEmployeeAdmin((e.EmployeID));
}
return false;
}
}
}
有什么问题吗?
I have this in my web config:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="Forms" />
<webServices>
<protocols>
<add name="HttpGet" />
<add name="HttpPost" />
</protocols>
</webServices>
默认验证cookie的超时值为30分钟,除非另有指定。
由于您声称在30分钟后注销,因此我认为您指定的是而不是。
要做到这一点,您必须在web中设置<form />
元素的timeout
属性。配置文件。
例如:-
<authentication mode="Forms">
<forms loginUrl="~/login.aspx" timeout="2880" />
</authentication>