View previous topic :: View next topic |
Author |
Message |
Miles
Joined: 06 Jan 2005 Posts: 1
|
Posted: Thu Jan 06, 2005 10:13 am Post subject: ASP.NET and C# cookie reading and writing |
|
|
Hi,
I'm new here, and I've decided to join your forum because I found several very helpful ASP.NET articles!
Here is my question. I want to know how to read and write cookies from ASP.NET. I want to use C# to create the cookies and I would appreciate it if somebody post a working ASP.NET example of cookie usage in C#.
Thanks all,
Miles |
|
Back to top |
|
|
paul
Joined: 11 Oct 2004 Posts: 128
|
Posted: Thu Jan 06, 2005 10:26 am Post subject: |
|
|
Welcome Miles
Using cookies in C# and APS.NET is very easy. The first example shows how to create a cookie in C#
Code: |
HttpCookie oCookie = new HttpCookie("YourCookie");
DateTime oDateTime = DateTime.Now;
oCookie.Value = "Your cookie value goes here...";
oCookie.Expires = oDateTime.AddHours(12);
Response.Cookies.Add(oCookie);
|
to read the same cookie in ASP.NET with C# do the following:
Code: |
HttpCookie oCookie;
oCookie = Request.Cookies["YourCookie"];
String YourCookieValue = oCookie.Value;
|
Paul _________________ World Countries | Survival Skills |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|