Answer: HttpCookie cookieWebInfo = new HttpCookie("WebInfo");
CookieWebInfo["Name"] = "DotnetFunda";
// here CookieWebInfo is an object of class HttpCookie
CookieWebInfo["Time"] = DateTime.Now.ToString();
cookieWebInfo.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(cookieWebInfo);
Here the HttpCookie class is under the System.Web namespace. Here 'Expires' sets the duration, when cookie expires.
Asked In: Many Interviews |
Alert Moderator