简体   繁体   中英

Cookie missing when called in a class

Good day..! I have some issue getting the value of my cookie when called in a class..

here's my code in my default.aspx.. I can retrieve the value on the when inside the aspx page

  HttpCookie myCookie = new HttpCookie("SAMPLE");
  myCookie["value"] = HttpUtility.UrlEncode(value);
  myCookie.Expires = DateTime.Now.AddDays(1d);
  Response.Cookies.Add(myCookie);

  if (Request.Cookies["SAMPLE"] != null)
        {
            string userSettings;
            if (Request.Cookies["SAMPLE"]["value"] != null)
            { userSettings = Request.Cookies["SAMPLE"]["value"]; }
 }

But when i called the cookie inside a class using this code HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["SAMPLE"]["value"]) it doesn't have any value.. Any idea..? Hope to hear from you soon..

Regards,

Link

You can replace with Response

 ....
 Response.Cookies.Add(myCookie);

if (Response.Cookies["SAMPLE"] != null)
{
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM