Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

wcf, cookie

Posted on 2013-11-18
6
Medium Priority
?
509 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:solution1368
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 10

Expert Comment

by:khan_webguru
ID: 39658406
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
0
 

Author Comment

by:solution1368
ID: 39658438
Thank. So we have no solution.
0
 

Author Comment

by:solution1368
ID: 39658439
Or it is impossible to use wcf services in this case?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 39659103
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:
http://asp.net-tutorials.com/state/cookies/

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>
0
 

Author Comment

by:solution1368
ID: 39660074
Thank you for your information.
0
 

Author Closing Comment

by:solution1368
ID: 39660079
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question