• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Can only read javascript cookie with .net in directory it was created?

I have a cookie set on landing page with javascript like below:

setCookie('cSizeSpeed', speedsize, 1);

   function setCookie(c_name, value, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
        document.cookie = c_name + "=" + c_value;

Open in new window

I can read it on the next page using this vb code, but only if that page is in the same directory where the javascript created it. How can I overcome this limitation?

   If Not IsNothing(Request.Cookies("cSizeSpeed")) Then
                strSpeedSize = Request.Cookies("cSizeSpeed").Value
        End If

Open in new window

1 Solution
Dave BaldwinFixer of ProblemsCommented:
I believe that the default is to set the path to the current directory.  This page http://stackoverflow.com/questions/5045053/set-cookie-wih-js-read-with-php-problem has examples of setting the path to '/' which is the root directory of the web site.  That should make it readable by any file at the web root or it's subdirectories.
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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now