Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCookie content/expiry clears when navigating away from pageCookie content/expiry clears when navigating away from page
Previous
 
Next
New Post
6/16/2011 5:52 AM
 
I am trying to quickly develop a little module (C#) to store a value from a dropdown in a cookie.

I have the module done and installed successfully and its been added to a page successfully.

The code behind the 'OnClick' for the button is just:

HttpCookie myCookie = new HttpCookie("DevTestPrefs");
myCookie.Values.Add("area", ddlArea.SelectedValue);
myCookie.Expires = Convert.ToDateTime("30 July 2011 01:31:11");
 
Response.Cookies.Add(myCookie);

I have the Cookies window open in FireFox so I can monitor the cookie live. I can see it being created and the values being correct (including the expiry), however, as soon as I navigate away from the page with the module on or even just refresh the page the cookie content/expiry gets cleared and is then nothing. The cookie itself remains but the content/expiry is cleared.

Am I missing something here? Should I be using something from the DNN framework itself to generate/manage cookies?

Any help would be greatly appreciated.

Kind regards,

Liam
 
New Post
6/16/2011 12:13 PM
 
After much searching of the forums etc. I found that it might have been down to the fact that I don't set the HttpOnly for my cookie.

I set this to true and try again but the values are still cleared. I go into the web.config file and even try setting the 'httpOnlyCookies' to false but it still doesn't work.

Struggling with this one.

Any help is still very much appreciated.

Kind regards,

Liam
 
New Post
6/16/2011 3:43 PM
Accepted Answer 
Fixed!

A mistake on my part caused this... *sigh*

I was trying to display the cookie results in a skin too. Didn't think it was relevant hence not including that in the original description but it turns out it was VERY relevant.

Anyways, to just display the cookie contents I was using:

Response.Cookies.Get("DevTestPrefs").Values.Get("area")


When I should have been using:

Request.Cookies.Get("DevTestPrefs").Values.Get("area")

Using 'Response' meant that each time the page loaded it reset the cookie values.

Anyways, my mistake but at least I got to learn from it and read into 'HttpOnly' etc. which does seem to be very important.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCookie content/expiry clears when navigating away from pageCookie content/expiry clears when navigating away from page


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out