Write the code which will create a cookie containing the user name DotnetFunda and the current date to the user computer. Set the cookie as that remains on the user computer for 10 days?

 Posted by Tripati_tutu on 11/1/2010 | Category: ASP.NET Interview questions | Views: 1937 | Points: 40

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

Here the HttpCookie class is under the System.Web namespace. Here 'Expires' sets the duration, when cookie expires.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response