Link to home
Start Free TrialLog in
Avatar of dparkes
dparkesFlag for United States of America

asked on

ASP will not delete cookie created with Javascript

Hi, I'm currently doing some maintenance on a site that uses JavaScript and plain ASP code (not Asp.Net), and I'm now very confused.

I am unable to delete a cookie for some reason.  I've tried the method they say to use everywhere:

Response.Cookies("LineItems").Expires = Date() - 1

And it does nothing.  

I'm wondering if the JavaScript cookie is the same as a regular cookie though, because I am using a cookie viewer (IECookiesView) and don't see the cookie there in any case.   Yet I can see view the cookie using the JavaScript command:

alert(document.cookie);

The cookie is set in JavaScript with a command like this:

document.cookie = "LineItems=this is what i want my cookie to be";

I'm very confused.  Is this not a cookie?  Why does it not show up in IECookiesView and undeletable with asp?


Avatar of hielo
hielo
Flag of Wallis and Futuna image

Have your tried something like:
Response.Cookies("LineItems").Expires=#May 10, 2002#
ASKER CERTIFIED SOLUTION
Avatar of slamhound
slamhound

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dparkes

ASKER

Slamhound, This gets me halfway there.

Yes it looks like my cookie was not correctly formatted.  Using a setCookie function, now it appears in the cookie explorer...

For some reason I had trouble calling the code you gave me and used this instead though, which in my case seems to work:

    function setCookie(Name, Value, Expire) {
        document.cookie = Name + "=" + escape(Value) + ";expires=" + Expire;
    }


However, the cookie is still not getting deleted using ASP code.

I've tried my original code, and hielo's above, but it's having no effect on the client side cookie.
Avatar of slamhound
slamhound

If formatting has fixed one problem I'd guess that it continues to be an issue.

Can you validate in your cookie explorer that everything is formatted properly. That the name is right, the value is right and the expiration date is right once JS creates it.

The other thing to try is
Response.Cookies("LineItems") = ""
or
Response.Cookies("LineItems") = Null

This way we can be sure that your ASP is manipulating the cookie even if it can't expire it.