Shopping Center CNC
Shopping Center CNC

Reputation: 99

Issue with remember me in asp mvc membership

I have https website and I am using membership for logins and my code in controller:

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();

and in 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" />

so its just keep login for 2 minutes and remember me is not working what should I do?

Upvotes: 1

Views: 180

Answers (1)

Shopping Center CNC
Shopping Center CNC

Reputation: 99

we should add this to system.web in web.config file an U can generate this key in iis but if U can access to iis U can use this code

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

Upvotes: 1

Related Questions