In code bellow i make login for save username and password in cookies client if it is correct username and password
Actually what i need
I need not using cookies to save username and password In place of cookies i need to using User.Identity.IsAuthenticated in place of cookies
How to do that ?
code below working without any problem
I working in visual studio 2015 with asp.net mvc 4
what i try
for login view get I can restore username and password in login if username and password logged before(no problem in that)
C#
public ActionResult Login()
{
UserAccount model = new UserAccount();
if (Request.Cookies["Login"] != null)
{
model.UserName = Request.Cookies["Login"].Values["UserName"];
model.Password = Request.Cookies["Login"].Values["Password"];
}
return View(model);From my code below i can login if username and password is correct also i can save username and password in cookies(no problem in that) .
Java
public ActionResult Login(UserAccount user)
{
using (ContainerClass db = new ContainerClass())
{
var usr = db.userAccount.Where(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault();
if (usr != null)
{
FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
Session["UserID"] = user.UserID.ToString();
Session["UserName"] = user.UserName.ToString();
if (user.RememberMe)
{
HttpCookie cookie = new HttpCookie("Login");
cookie.Values.Add("UserID", user.UserID.ToString());
cookie.Values.Add("UserName", user.UserName);
cookie.Values.Add("Password", user.Password);
cookie.Expires = DateTime.Now.AddDays(15);
Response.Cookies.Add(cookie);
}
return RedirectToAction("LoggedIn", "Account");
}
else
{
ModelState.AddModelError("", "Username or Password is wrong");
}
}
return View(user);
}
Amit Kumar SinghRank #562 · 4.3K reputationPosted Dec 9, 2016, 6:45 PM EST
Krishna Rajput SinghRank #605 · 4K reputationPosted Dec 10, 2016, 3:58 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts