Cookie 视图状态未在 AjaxControlToolkit 中维护

Cookies viewstate are not maintaining in AjaxControlToolkit

我在下面的控件中有 cookie 和视图状态。 此 ajax 控件用于上传多个文件图像。

protected void OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {           
        int userid = 25;
        DAL_Cart objdalcart = new DAL_Cart();
        if (Viewstate["Imagestringname"] == null)
        {
            objdalcart.InsertTempImage(userid, ImageName, 1);
        }
        else
        {
            objdalcart.InsertTempImage(userid, ImageName, 0);
        }
        Response.Cookies["JewelleryUserCookiesUserId"].Value = Convert.ToString(userid);
        Response.Cookies["JewelleryUserCookiesUserId"].Expires = DateTime.Now.AddYears(1);
        Viewstate["Imagestringname"] = ImageName + ",";
    }

问题是当我尝试在同一页面中按钮的不同点击事件上检索视图状态值或 Cookies 值时,我无法检索值

 protected void lnkcheckout_Click(object sender, EventArgs e)
    {
      if (Request.Cookies["JewelleryUserCookiesUserId"] == null || Request.Cookies["JewelleryUserCookiesUserId"].Value == "")
            {
             }
    if (Viewstate["Imagestringname"] != null)
        {}
     }

对于这两种情况,它都处于 if 条件。对于视图状态,我在母版页上放置了 Enableviewstate=true。知道为什么吗?

评论

Want ajax multiple file upload on my button click event

var c = new HttpCookie("JewelleryUserCookiesUserId");
c.Value =  Convert.ToString(userid);
c.Expires = DateTime.Now.AddYears(1);

Response.Cookies.Add(c);

请注意:这是不安全的。客户端可以操纵 cookie...