Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate cookies?

Tags:

c#

.net

asp.net

I have an application that leverages a cookie to support a quasi-wizard (i.e. it's a set of pages that are navigated to by each other, and they must occur in a specific order, for registration).

When the Logon.aspx page is loaded - the default page - the browsers cookies look right.

Here we have only one cookie.

There's one cookie and it has the right value. This ensures that the next page, which is an enrollment agreement, knows that it was loaded from the Logon.aspx page. However, when I get to that page the browsers cookies look much different:

Now we have two of the same cookie.

Now we have two of the same cookie.

This doesn't appear to be causing any real issues - but I can't be sure it won't. So, let me show you the code I'm using to set the cookie (because maybe there's something wrong with it):

if (!this.IsPostBack)
{
    Utility.HandleReferrer(Request, Response, "Logon.aspx");
    Response.Cookies["lastpage"].Value = "Enroll.aspx";
}

and the HandleReferrer method looks like this:

static public void HandleReferrer(HttpRequest request, HttpResponse response, string expectedReferrer)
{
    var cookie = request.Cookies["lastpage"];
    if (cookie != null && cookie.Value.ToLower().Contains(expectedReferrer.ToLower()))
    {
        return;
    }

    response.Redirect("Logon.aspx");
}

So, why in the world does it duplicate this cookie? It doesn't ever seem to create more than two.

like image 351
Mike Perrenoud Avatar asked Jan 28 '26 11:01

Mike Perrenoud


1 Answers

I suggest you do one of the following.

First, get the latest glimpse and try again.

If it is still showing 2 cookies with that name then get firebug and/or fiddler and look at it that way. If I had to take a guess I'd say there's either something wrong in glimpse or something wrong in how you are interpreting the results. Perhaps glimpse is showing what cookies existed before and then after the request was processed?

A third option is to simply emit the cookies collection from your own .net code. Something like:

foreach(HttpCookie cookie in request.Cookies) {
  Response.Write(String.Format("{0} = {1}", cookie.Name, cookie.Value));
}

and see what happens.

like image 85
NotMe Avatar answered Jan 30 '26 03:01

NotMe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!