$0.7

How can i store cookies in browser in c#?

Ask a question+
0

How can i store cookies in browser in c#?

add comment

1 Answer

0
HttpCookie myCookie = new HttpCookie("MyTestCookie");
DateTime now = DateTime.Now;

// Set the cookie value.
myCookie.Value = now.ToString();
// Set the cookie expiration date.
myCookie.Expires = now.AddYears(50); // For a cookie to effectively never expire

// Add the cookie.
Response.Cookies.Add(myCookie);

Response.Write("<p> The cookie has been written.");

also

HttpCookie userInfo = new HttpCookie("userInfo");  
userInfo["UserName"] = "Annathurai";  
userInfo["UserColor"] = "Black";  
userInfo.Expires.Add(new TimeSpan(0, 1, 0));  
Response.Cookies.Add(userInfo);

also

HttpCookie StudentCookies = new HttpCookie("StudentCookies");
StudentCookies.Value = TextBox1.Text;
StudentCookies.Expires = DateTime.Now.AddHours(1);
Response.Cookies.Add(StudentCookies);
Gor13666_ 900
add comment

Your Answer