【问题标题】:Issue with remember me in asp mvc membership在 asp mvc 成员中记住我的问题
【发布时间】:2017-06-11 07:31:11
【问题描述】:

我有 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 分钟并记住我不工作 我该怎么办?

【问题讨论】:

  • 我认为这与 SSL 无关。
  • \你的问题是超时卡在2吗?
  • 感谢您的回答,我不知道它的 2 分钟或者它只是不工作,并且在短时间内它会退出(我不知道它是 2 分钟或更长时间)
  • 我认为它是 ssl,因为我有另一个带有 http 且工作正常的网站
  • 你使用 IIS 吗? cookie 可能会在应用程序池回收后失效,通常在 20 分钟左右或重新启动应用程序时。

标签: c# asp.net-mvc https asp.net-membership


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-15
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多