-
httpcookie problem
Hi there,
I can't seem to figure out why the cookie I've created doesn't get written
to disk...i.e. first time the cookie is created...and saves the value I've
assigned to key...it works great till I reboot my machine from where I'm
making the request from...it then creates a cookie again...it's although the
cookie was not created. Can someone please tell me what I'm doing
wrong...much appreciated.
This is what its doing:
* bootup
* make request - creates cookie
* make request - look-up cookie value
* make request - look-up cookie value
* make request - look-up cookie value
* reboot
* make request - creates cookie
* make request - look-up new cookie value
* make request - look-up new cookie value
* reboot
* make request - creates cookie
....etc.
This is what I expect it to do:
* bootup
* make request - creates cookie
* make request - look-up cookie value
* make request - look-up cookie value
* make request - look-up cookie value
* reboot
* make request - look-up cookie value
* make request - look-up cookie value
* reboot
* make request - look-up cookie value
....etc.
//////// CODE BEGIN ////////
if(context.Request.Browser.Cookies) { // Browser accepts cookies.
HttpCookie http_cookie = context.Request.Cookies["Dan"];
if(http_cookie == null) { // Cookie does not exist.
context.Response.Write("NO COOKIE");
http_cookie = new HttpCookie("Dan");
http_cookie.Values["Age"] = "21";
context.Response.Cookies.Add(http_cookie);
}else{ // Cookie exists.
// Get value for user id.
age = Convert.ToInt64(http_cookie["Age"]);
context.Response.Write("COOKIE - " + Convert.ToString(age));
}
}
//////// CODE END ////////
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks