2013-08-30 25 views

回答

0

爲了記住我的功能你的行動會去這樣

[HttpPost] 
public ActionResult Login(LoginModel model) { 

//Implementaion for authorization 
....... 

var authTicket = new FormsAuthenticationTicket(
    1, 
    userId, //user id 
    DateTime.Now, 
    DateTime.Now.AddMinutes(20), // expiry 
    rememberMe, //boolean value true for remember 
    "", //roles 
    "/" 
); 

HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); 
Response.Cookies.Add(cookie); 

return RedirectToAction("Index"); 
} 
+0

複製從其他地方的代碼,你至少應該告訴他們從何處取得它。在這種情況下,只是重定向到源:http://stackoverflow.com/questions/5619791/implementing-remember-me-feature-in-asp-net-mvc –

+0

謝謝bt它需要記住我的價值永遠是假的,rememberMe不是類的屬性。 –

+0

你將不得不添加'rememberMe'類。因此在創建票證時,適當的值將被設置。 –