473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

REPOST - Please can someone help me with a simple cookie question

Hello,

I am having a problem setting and resetting cookies. I'm sure I just
doing something really stupid as this is such a basic issue, but I can
find any answer. Please can someone help me?

The following code is a complete page that demonstrates my problem. If
you save this as an .aspx and load it in a browser, it tells you it is
creating the cookie. If you reload the page, it tells you it is changing
the value. If you reload it again, it tells you it is removing the
cookie.

All of this is exactly what I expected, except that it didn't work. If
you close the browser window at any stage and reload the page, it always
shows the "creating" message. So, it seems that it's not actually
creating the cookie at all.

Please can someone help me here. I've spent hours trying to solve what
should be a really simple problem. TIA
<%@ Page Language="C#" Debug="true" %>
<script runat="server">

void Page_Load(Object o, EventArgs e) {
string cookieName = "fred";
if (Request.Cookies[cookieName] == null) {
// the cookie does not exist. Create it
x.Text = "Creating a new cookie";
HttpCookie cookie = new HttpCookie(cookieName, "newcookie");
cookie.Expires = DateTime.Now.AddMonths(1);
Response.Cookies.Add(cookie);
} else if (Request.Cookies[cookieName].Value == "newcookie") {
// the cookie was created last time this page was called
x.Text = "Changing value from " + Request.Cookies[cookieName].Value
+ " to oldcookie";
Response.Cookies[cookieName].Value = "oldcookie";
} else {
// the cookie was created before the previous call to this page.
Delete it
x.Text = "Removing the cookie whose value is " +
Request.Cookies[cookieName].Value;
Response.Cookies.Remove(cookieName);
}
}

</script>

<html>
<body>
<asp:Literal ID="x" EnableViewState="false" RunAt="server" />
</body>
</html>
--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
0 1217

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wasian_god | last post by:
yea im knew to python, and i kno this is a very simple question. im trying to make a shell dat first says I want a cookie. Then it waits for the user to input the word cookie. while cookie is not...
1
by: koen colen | last post by:
Hello group, I hope you guys can help me out, I am modifying a piece of code from Joe Norman, I did found the code here: http://www.intranet2internet.com/public/default.asp?PAGE=sscript&ID=3 ...
1
by: Anthony | last post by:
Sorry about the repost but i didn't get any responses.... I am trying to make a simple page display a rss news feed.. I don't want the web server to connect to remote site because it doesn't...
1
by: Yannick Turgeon | last post by:
Hello, This is a repost (see under the "dotted" line) from 2 days ago. Hope someone could help. Norton Antivirus 2003 is installed on this computer. Could it cause a problem? Another...
3
by: Calvin KD | last post by:
Hi everyone, Can someone tell me what's wrong with the way that i read a cookie as below: private void Page_Load(object sender, System.EventArgs e) { Response.Cookies.Clear(); HttpCookie...
67
by: Scott M. | last post by:
Can anyone give me any ideas on why VS.NET 2003 running on XP Pro. (P4's with 1GB RAM) would take over 3 minutes to simply create a new ASP.NET Web Application on http://localhost? It seems that...
3
by: Beavis | last post by:
I hate to repost a message, but I am still at the same point where I was when I originally posted, and hopefully someone else will see this one... Ok, so I have gone off and documented the...
6
by: alex.kemsley | last post by:
Hi guys, I am trying to write a simple script in vain. I need it to first check to see if the cookie exists then if not write one with two variable var ref = document.referrer var page =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.