Solved

wcf, cookie

Posted on 2013-11-18
6
506 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
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!

 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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