Cookies not persisting accross pages ASP.NET

B

Brano

HI all,

I have this problem I have two pages on one I use this code to set some
cookies:

Response.Cookies("cokFirstName").Expires = DateTime.MaxValue
Response.Cookies("cokFirstName").Value = txtForename.Text
Response.Cookies("cokMiddlename").Value = txtMiddlename.Text

If I break the code there and check the cookies they all have the right
values

However after I redirect to another page and try to read these cookies
I get this error

Referenced object 'Item' has a value of 'Nothing'.

Why is this happening ??
PLEASE HELP
 
J

Jason Hales

After you've redirect are you then referring to them via the Request
object, rather than Response?

Are you redirecting to a different virtual path, if so consider setting
the cookie.Path property
 
B

Brano

Hi yes I am,

I have found the problem it is that ASP.NET only supports up to 20
cookies and I had about 45 so the last 20 always overwritten the first
20 cookies...

and i was only testing the first one...

Sorted it out using cookie keys

Response.Cookies("Key")("Name") = string
 
J

Jason Hales

I never knew that limit existed

I guess you could serialise all of your cookies into a single cookie
value - but then you might exceed the maximum length for a cookie -
which I believe is 64K

Mind you that's an awful lot of stuff your saving as cookies
 
J

Juan T. Llibre

re:
I have found the problem it is that ASP.NET only supports up to 20 cookies

The number of cookies is not limited by ASP.NET.
It is controlled by the browsers, per the W3C's 2109 RFC.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dninstj/html/cookietheory.asp

Browser Cookie restrictions

Browsers place restrictions on the number of cookies that can be held at any one time.

The restrictions are:
a.. 20 cookies maximum per domain.
b.. 4096 bytes per cookie description.
c.. 300 cookies overall maximum.

RFC 2109 says at least these maximums.
Netscape's specification and browsers say at most these maximums.

There is now a pref in Mozilla and Firefox that allows you to modify the maximum cookies per host.

IE still implements RFC 2109. I don't know if IE7 will address that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top