Link to home
Start Free TrialLog in
Avatar of solution1368
solution1368

asked on

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.


wcf:
 public string AddCookie(string cookieName, string cookieValue, int cookieLiveInHour)
        {
            HttpCookie myCookie = new HttpCookie(cookieName);
            myCookie.Value = cookieValue;
            myCookie.Expires = DateTime.Now.AddHours(cookieLiveInHour);
            HttpContext.Current.Response.Cookies.Add(myCookie);
            return "Added";
             
        }

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

error:
See attached
c.png
Avatar of khan_webguru
khan_webguru
Flag of Australia image

Hello,

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>

Regards,
khan.webguru
Avatar of solution1368
solution1368

ASKER

Thank. So we have no solution.
Or it is impossible to use wcf services in this case?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your information.
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.