Unable to retrieve cookie set via javascript

  • Thread starter Thread starter Josh T
  • Start date Start date
J

Josh T

As of now I am setting a cookie on my aspx page via javascript,

function SetCookie(cookieName, value, minutesToExpire)
{
ClearCookie(cookieName);

var expireDate = new Date();
var cookieValue;
expireDate.setMinutes(expireDate.getMinutes() +
minutesToExpire);
cookieValue = cookieName + "=" + escape(value) +
";expires=" + expireDate.toGMTString();
document.cookie = cookieValue;

}

I know the cookie is created and set correctly (thx to a nifty cookie
manager). After the cookie is set, i have the javascript redirect the
user to a second aspx page. This second page is where I'm trying to
retrieve the cookie

HttpCookie cookie = Response.Cookies.Get("myCookieName");

But the code either shows that there is no cookie set, or that the
value is empty. Any ideas? Should i be setting a path for the cookie
or am i totally off base here? Any/all thoughts and solutions are
welcome.

Thanks,
Josh T
 
Josh said:
As of now I am setting a cookie on my aspx page via javascript,

function SetCookie(cookieName, value, minutesToExpire)
{
ClearCookie(cookieName);

var expireDate = new Date();
var cookieValue;
expireDate.setMinutes(expireDate.getMinutes() +
minutesToExpire);
cookieValue = cookieName + "=" + escape(value) +
";expires=" + expireDate.toGMTString();
document.cookie = cookieValue;

}

I know the cookie is created and set correctly (thx to a nifty cookie
manager). After the cookie is set, i have the javascript redirect the
user to a second aspx page. This second page is where I'm trying to
retrieve the cookie

HttpCookie cookie = Response.Cookies.Get("myCookieName");

But the code either shows that there is no cookie set, or that the
value is empty. Any ideas? Should i be setting a path for the cookie
or am i totally off base here? Any/all thoughts and solutions are
welcome.

Thanks,
Josh T

Try Request.Cookies instead of Response.Cookies
 

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

Cookies C# 3
Non-persistent cookie 1
Weird Cookie Behaviour 1
problem with cookies 3
Maybe Partial? 9
Javascript and cookies 2
The folloing javascript code does not compile. 10
Cookie is not created why ? 2

Back
Top