Can somebody tell me how to set a cookies & how to retrive cookie values on the other page???? Why cookies are used???? If we have to pass info from one page to another,for dat we can use QuerySTring,y Cookies???

ASP.NET Cookies

A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.

Create a cookie

HttpCookie c1=new HttpCookie("name","value");
 c1.Expires = DateTime.Now.AddDays(5);
 c1.Path = "/samplesite";
 Response.Cookies.Add(c1);

Retrieve cookies

String value=Request.Cookies["name"].Value;

A cookie is a small peace of information stored in client system in a plain format. cookies r two type one in inmemory cooke and second one is persistent cookie. inmemory cooke has no expiry date. these cookies r there in a system when user browsing the website. when user close the browser inmemory cookies r deleted. persisten cookie
has expiry date and time, that means we can delete the cookie programmatically. persistent cookie will remain in the memory even after user close the browser. By default persisten cookie will be in memory for 50 years.

declaration of cookie:
Httpcookie obj = new Httpcooki();
obj.value="somthing u want";
Response .Cookie.Add(obj);

fetching the cookie in different pages:
request.cookie["value"].Tostring();

we we can use cookies rather querystring is querystring data will display on the url address, and we can't send secret values.in query string u can send 2kb information only in cookis u can send up to 4kb

hi frnds,tell me one thing

c1.Expires = DateTime.Now.AddDays(5);

5 in the above line means cookie will expire after 5 days or 5 hours.
I want the cookie to be expired after 20 minutes,then what should i write?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.