Guest User

Guest User

  • Tech Writer
  • 515
  • 46k

About Session or Cookies

Jan 23 2021 5:57 PM
Hello,
hope everyone is doing fine.
 
I need help keeping my session alive in my MVC web application, until User logged out.
My web application should automatically redirect to the dashboard page always.
 
I tried cookies also (I have first created Session["UserId"] and then kept that Session in cookies), I can see cookies are created in browser, but still my web application is getting log out. 
 
I have created cookies using :  
HttpCookie hqloginCookie = new HttpCookie("hqLogin");
//Set the Cookie value.
hqloginCookie.Values["Name"] = Session["Name"].ToString();
hqloginCookie.Values["Email"] = Session["Email"].ToString();
hqloginCookie.Values["UserId"] = Session["UserId"].ToString();
hqloginCookie.Values["Password"] = Session["Password"].ToString();
hqloginCookie.Path = Request.ApplicationPath;
hqloginCookie.Expires = DateTime.Now.AddDays(365);
Response.SetCookie(hqloginCookie);
Response.Cookies.Add(hqloginCookie);
 
Using Cookies on my dashboard page using : 
HttpCookie cookie = HttpContext.Request.Cookies.Get("hqLogin");
 
I  
 
 
 

Answers (3)