views:

43

answers:

1

On my content page I have the code (in page_load):

    if (Master.pageAction == "remove")
    {
        int removeProductID = int.Parse(Request.QueryString["ID"]);
        int removeOptionID = int.Parse(Request.QueryString["optID"]);
        Master.myBasket.removeFromBasket(removeProductID, removeOptionID);
        //Response.Redirect("viewBasket.aspx");
    }

The function remove from basket is defined as:

// Removes item from a basket
public void removeFromBasket(int itemsID, int optionsID)
{
    Page myPage = (Page)HttpContext.Current.Handler;

    this.setCookieString("");
    myPage.Response.Write("done");
}

And it calls:

// Sets cookie date
public void setCookieString(string cookiesData)
{
    Page myPage = (Page)HttpContext.Current.Handler;
    HttpCookie basketCookie = new HttpCookie("basket");
    basketCookie["items"] = cookiesData;
    basketCookie.Expires = DateTime.Now.AddDays(7d);
    myPage.Response.Cookies.Add(basketCookie);
}

I use the setcookiestring function on other pages and it works fine, but this function (removing from the basket) isn't setting the cookie! It is writing "done" to the top of the page, so the functions are executing.

No warnings, no errors, it's just not updating the cookie.

A: 

The problem came from the cookie initially being set by Javascript with no path= attribute being set. Javascript defaults the cookie path to the current folder, whilst ASP.net defaults to /.

Setting the path=/ in the Javascript set cookie method resolved this issue.

Tom Gullen