Question

I'm trying to figure this one out, but all I seem to come across are posts telling how to create one, which is not really my problem. I'm simply wondering, if such a practice exists, when a good (or the correct for that matter) time to create a cookie is.

In my webpage, based on asp.net mvc, I have some tags that acts as a filter on a list of elements on my page. I want to remember the selection of tags every time the user comes back to that page. Using HTTPCookie, the cookie stores my information just fine, but as I mentioned above; when is the right time to set it? When the user leaves the page? Every time a new tag is clicked? And, if so, do I just create a new cookie with the same name over again to overwrite the old one with new information?

Was it helpful?

Solution

Ok, so I sort of figured this one out myself after some discussion with colleagues. In my controller, I ended up checking if a tagged was clicked, and if it was I either created a new cookie (first time click) or overwrote the old one with new information.

And, if the tag was empty, but a cookie was set for that user, I checked for the named cookie and repopulated my tag selection. Works like a charm.

I'm not sure this is the 'correct' way of doing it, so I'd love some feedback if anyone is interested in commenting later on :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top