Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

Write the code that creates a cookie containing the user name R4R and the current date to the user computer. Set the cookie to remain on the user computer for 30 days?
Code:
HttpCookie cookUserInfo = new HttpCookie("UserInfo");
CookUserInfo["Name"] = "R4R";
CookUserInfo["Time"] = DateTime.Now.ToString();
cookUserInfo.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookUserInfo);

Description:
"HttpCookie" :The HttpCookie class is under System.Web namespace.
"CookUserInfo" :is the object of class HttpCookie
"Expires": is the property that sets the duration,when cookie expire.