在 asp mvc 成员中记住我的问题

Issue with remember me in asp mvc membership

我有 https 网站,我正在使用会员登录和 我在控制器中的代码:

int timeout = rememberme ? 2880 : 2; // Timeout in minutes,525600 = 365 days
var ticket = new FormsAuthenticationTicket(username, rememberme, timeout);
string encrypted = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
cookie.Expires = DateTime.Now.AddMinutes(timeout);//My Line
Response.Cookies.Add(cookie);

string returnurl = FormsAuthentication.GetRedirectUrl(username, rememberme);
if (string.IsNullOrEmpty(returnurl)) returnurl = "/Panel/Login";

if (string.IsNullOrEmpty(returnurl)) returnurl = "/Panel/Login";
if (rol == "User")
    return Redirect("/Panel/Dashboard");
else if (rol == "Admin")
    return Redirect("/Panel/DashboardAdmin");

return View();

并在 we.config 中:

<httpRuntime targetFramework="4.6.2" executionTimeout="100000000" maxRequestLength="2147483647" />
<authentication mode="Forms">
  <forms loginUrl="~/Panel/Login" requireSSL="true" slidingExpiration="true" />
</authentication>
<httpCookies httpOnlyCookies="true" requireSSL="true" />

所以它只是保持登录 2 分钟并记住我不起作用 我该怎么办?

我们应该将其添加到 web.config 文件中的 system.web U 可以在 iis 中生成此密钥,但如果 U 可以访问 iis U 可以使用此代码

    <machineKey
  decryptionKey="1513F567EE75F7FB5AC0AC4D79E1D9F25430E3E2F1BCDD3370BCFC4EFC97A541"
  validationKey="32CBA563F26041EE5B5FE9581076C40618DCC1218F5F447634EDE8624508A129"
  decryption="AES"
  validation="SHA1"
  />