Implement Remember me and copy paste url in MVC3

时间:2015-07-28 15:54:01

标签: asp.net-mvc-3 cookies c#-3.0 remember-me

The requirement is implement "Remember Me" and "Copy Paste url on browser" functionality using MVC3.

  1. I am using Active Directory (LDAP) for authenticate user, on success create Cookies and store a value.

  2. 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.

0 个答案:

没有答案
相关问题