I am using the following C# code in a function called by a
button click:
HttpCookie cookie = new HttpCookie("UserName");
cookie.Value = tbUserName.Text;
Response.Cookies.Add(cookie);
When I go to look for this cookie on my system, I cannot
find it anywhere. If I close my browser, then open the
browser again and try to reload the page, I get ASP.NET
errors because of a null reference when the cookie was not
found. Obviously, I need to add some code to check if the
cookie exists and if not load the page with defaults, but
why is the cookie not created? Am I missing something? I
am testing this on a Windows XP Professional system
running IIS. 4 1037
If you want the cookie to be kept when you close your browser, you must set
the Expires property of the cookie to something; this will make a persistent
cookie.
If you don't do so (like in your example), a temporary cookie is created. A
temporary cookie is lost when the browser is closed, while a persistent
cookie isn't.
--
To reply, remove a "l" before the @ sign.
Arnaud Weil - MCT, MCSD.Net, MCAD.Net
Is there a way to set the Expires property so that the
cookie does not expire? -----Original Message----- If you want the cookie to be kept when you close your
browser, you must setthe Expires property of the cookie to something; this
will make a persistentcookie.
If you don't do so (like in your example), a temporary
cookie is created. Atemporary cookie is lost when the browser is closed,
while a persistentcookie isn't. -- To reply, remove a "l" before the @ sign.
Arnaud Weil - MCT, MCSD.Net, MCAD.Net
.
You have to set the expires date to one that's very far in the future
<an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl... Is there a way to set the Expires property so that the cookie does not expire?
-----Original Message----- If you want the cookie to be kept when you close your browser, you must setthe Expires property of the cookie to something; this will make a persistentcookie.
If you don't do so (like in your example), a temporary cookie is created. Atemporary cookie is lost when the browser is closed, while a persistentcookie isn't. -- To reply, remove a "l" before the @ sign.
Arnaud Weil - MCT, MCSD.Net, MCAD.Net
.
Thanks for your help! It works now! -----Original Message----- If you want the cookie to be kept when you close your
browser, you must setthe Expires property of the cookie to something; this
will make a persistentcookie.
If you don't do so (like in your example), a temporary
cookie is created. Atemporary cookie is lost when the browser is closed,
while a persistentcookie isn't. -- To reply, remove a "l" before the @ sign.
Arnaud Weil - MCT, MCSD.Net, MCAD.Net
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Henry Hartley |
last post by:
I've got a PHP system working on a development server (Windows
2000/IIS5/PHP 4.3.3) but it doesn't seem to be working quite right on
the testing server (same except PHP 4.2.3). I upgraded the PHP...
|
by: Asad |
last post by:
I am trying to get a cookie going on my site. Here is the code first:
function setCookie()
{
if(document.cookie == "")
{
var someDate = new Date("December 31, 2023");
var expiryDate =...
|
by: SL |
last post by:
Hi all...
I am currently porting an application from ASP to ASP.NET.
I seem to be experiencing different behavior when issuing cookies in
ASP.NET vs. what I experienced in ASP.
The name of...
|
by: Ash |
last post by:
Hi
I'm creating a cookie on my site, and adding values to it, namely a userid
and a groupid:
Function1:
oCookie.Values = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);...
|
by: Ash |
last post by:
Hi
I'm creating a cookie on my site, and adding values to it, namely a userid
and a groupid:
Function1:
oCookie.Values = siteID.ToString();
HttpContext.Current.Response.Cookies.Set(oCookie);...
|
by: Wysiwyg |
last post by:
After a server created cookie is processed on the client I want it removed,
cleared, or expired in the javascript block but have been unable to do this.
If I set a cookie value in the server code...
|
by: Doug |
last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on
"search.mydomain.com"; hence, a new session and cookie are being created on
every sub-domain.
This is occuring because...
|
by: Doogie |
last post by:
Hi,
I am having a problem reading a cookie that I can see is being
created. I create the cookie in my global.aspx.vb page like so:
Sub Session_Start(ByVal sender As Object, ByVal e As...
|
by: rjoseph |
last post by:
Hi Guys
I hope this is an easy one for you.
Basically I have a page on my website that creates a javascript based cookie on the users pc. The contents of the cookie when created looks as...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |