ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ASP.NET and C# cookie reading and writing

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> .NET Programming (ASP.NET, VB.NET, C#)
View previous topic :: View next topic  
Author Message
Miles



Joined: 06 Jan 2005
Posts: 1

PostPosted: Thu Jan 06, 2005 10:13 am    Post subject: ASP.NET and C# cookie reading and writing Reply with quote

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
View user's profile Send private message
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Thu Jan 06, 2005 10:26 am    Post subject: Reply with quote

Welcome Miles Smile

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> .NET Programming (ASP.NET, VB.NET, C#) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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

SQL Tutorial