The requirement is implement "Remember Me" and "Copy Paste url on browser" functionality using MVC3.
I am using Active Directory (LDAP) for authenticate user, on success create Cookies and store a value.
On NEXT visit check for cookies values not null and return to requested url or else return to Login Page.
Need help implementing "Remember Me" and "Copy Paste url on browser" functionality using MVC3.
The below code is working fine to validate a user in Active Directory:
if (ModelState.IsValid)
{
//LoginCheck() validate user in Active Directory.
if (ModelState.IsValid && LoginCheck(model.UserName, model.Password))
{
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
I am able to create a Form authenticate object and add to the cookies on a successful login.
//create the authentication ticket
var authTicket = new FormsAuthenticationTicket
(
1,
model.UserName, //user id
DateTime.Now,
DateTime.Now.AddMinutes(20), // expiry
model.RememberMe, //true to remember
"", //roles
"/"
);
//encrypt the ticket and add it to a cookie
HttpCookie cookie = new HttpCookie("FormsCookieName", FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(cookie);
What I don't understand is how to check a cookies values on next visit and handle copy-paste url.