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

on Feb 26, 2018 04:13 AM

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.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Feb 26, 2018 11:00 PM


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);