Add and retrieve cookies using C# in ASP.Net MVC

Last Reply one year ago By mukesh1

Posted one year ago

Want to add id of user in cookies when user first login, and cookies will remove after 320 days.

Mainly i am working in mvc using entity framework with database first approach.

You are viewing reply posted by: mukesh1 one year ago.
Posted one year ago


HttpCookie myCookie = new HttpCookie("ID"); 
myCookie["ID"] = Aunthicate.ID.ToString(); 
//myCookie.Expires = DateTime.Now.AddDays(-1d); 

 and for get cookies value in session

Session["ID"] = Server.HtmlEncode(Request.Cookies["ID"].Value);