Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All Experts,


C#
HttpCookie h = new HttpCookie("start");
        //Set the time for the test here
        DateTime dt = DateTime .Now .AddSeconds(60);
        h.Value = dt;
        Response.Cookies.Add(h);


i got error near the h.value = dt;

thank u for your valuable replay
Posted
Updated 2-Nov-11 8:30am
v2

1 solution

Just try h.Value = dt.ToString();.

A cookie only takes text as the value.

As mentioned here[^] -
"Cookies can store values only of type String. You must convert any non-string values to strings before you can store them in a cookie. For many data types, calling the ToString method is sufficient. For more information, see the ToString method for the data type you wish to persist.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900