2017-08-01 123 views
2

我想實現記住我的功能到我的MVC應用程序,我想通過使用MVC身份來實現它。通常會話在一個小時後過期,但是,每當用戶選中記住複選框時,到期時間將變爲一週。我正在使用cookie認證。 解決此問題的正確方法是什麼?記住我的功能與MVC身份

+0

你正在使用什麼樣的認證? –

+0

檢查[this](https://stackoverflow.com/questions/5619791/implementing-remember-me-feature-in-asp-net-mvc?noredirect=1&lq=1)之一。它會幫助你。 – Lifewithsun

+0

我正在使用cookie認證 – Karolis

回答

2

你只需要IsPersistent設置爲true,當你在用戶身份登錄做到這一點(你想的還記得我複選框外部流量可能也還添加一些實物)

如果有人檢查複選框IsPersisten應該爲true,否則爲false。

AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = <rememberMe> }, <userIdentity>);