Handling Multiple Cookies


I'm currently working on an MVC project that handles one step of a 2 step authentication via cookie data.  I want to have multiple cookies that expire at different times, though I've noticed that all of my cookies are being stored in one "cookie file" (as it appears in windows explorer when you look at the cookies).

I can access the cookies and their data separately correctly within the code, but it seems if I expire one or the other, it causes both of them to be no longer passed by the browser.

Can I have multiple cookies in the same file with multiple expiration date/times?  Can a single site have multiple cookie files?

Thanks for any input!
LVL 12
Who is Participating?
guru_samiConnect With a Mentor Commented:
4KB per cookie.
Most browsers support cookies of up to 4096 bytes. ....

Most browsers allow only 20 cookies per site; if you try to store more, the oldest cookies are discarded. Some browsers also put an absolute limit, usually 300, on the number of cookies they will accept from all sites combined.

- Yes you can create more than one cookie with separate expiration date.
- Cookies are stored per domain, so you will see a single file per domain.

- Are they separate cookie or storing multiple values in same cookie?

Can you share you code.
piattndAuthor Commented:
They are multiple cookies and each cookie has multiple values.  Is the cookie limit of 4KB actually the individual cookie size or is that the file size that represents all cookies for that domain?

I think I may have figured out the expiration thing.  The expiration listed on the file itself I believe is the date of the longest valid cookie.  I'm doing more testing on the expiration issue, but I'll post my code if I can't get it figured out.
piattndAuthor Commented:
I was able to resolve the issue.  My code for setting the expiration was not actually returning the cookie again, so it was a bonehead error.

I still have the question though on the cookie size limit.  I know the typical limit to stick by is 4KB, but is that for the total size of all cookies for the domain (the size of the single cookie file) or is that truly the size of each individual cookie?
piattndAuthor Commented:
Sorry it took me so long to close.  Thanks a lot for your help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.