wcf, cookie

I have below codes and I don't know why the error is still occurred (see attached).
all I want to do is use the WCF addCookie to add cookie into the client browser.

 public string AddCookie(string cookieName, string cookieValue, int cookieLiveInHour)
            HttpCookie myCookie = new HttpCookie(cookieName);
            myCookie.Value = cookieValue;
            myCookie.Expires = DateTime.Now.AddHours(cookieLiveInHour);
            return "Added";

string addCookieEmail = ServiceGeneric.AddCookie("someName", Request.Params["email"],12);

See attached
Who is Participating?
Miguel OzConnect With a Mentor Software EngineerCommented:
Yes, WCF is not needed for this. HttpContext.Current.Response only exists in the context of an aspx page.
You can create a cookie in the server when your page initially loads or post back in the Page_Load event. For example the link below creates in the ColorSelector_IndexChanged event:

Alternative: You can use Javascript or jquery to create the cookie in the page as per examples below:
//Create expiring cookie, 7 days from then:
$.cookie('the_cookie', 'the_value', { expires: 7 });

Open in new window

<links removed - GaryC132>

The cookie may exist, but to get them you need to have a page, a request from the client and the connection with their browser so to been able to read the cookies, that lives on the browser.

If you make this call from inside a thread, or a process, or on the end of the Page, or anywhere outside the Page, then the HttpContext.Current is null, and/or the HttpContext.Current.Request is null.

<link removed - GaryC123>

solution1368Author Commented:
Thank. So we have no solution.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

solution1368Author Commented:
Or it is impossible to use wcf services in this case?
solution1368Author Commented:
Thank you for your information.
solution1368Author Commented:
after the expert explains. there is no solution in my case because of the limited property in .net framework. Thank you for the expert's time and effort.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.