在我的内容页面上,我有代码(在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");
    }

从篮子中删除的功能定义为:

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

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

它打电话:

// 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);
}

我在其他页面上使用setCookiestring函数,它可以正常工作,但是此功能(从篮子上删除)并没有设置cookie!它正在写入页面顶部的“完成”,因此功能正在执行。

没有警告,没有错误,只是没有更新cookie。

有帮助吗?

解决方案

问题来自最初由JavaScript设置的cookie path= 设置属性。 JavaScript默认为当前文件夹的cookie路径,而ASP.NET默认为 /.

设置 path=/ 在JavaScript集cookie方法中,解决了此问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top