Solved

wcf, cookie

Posted on 2013-11-18
6
493 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 35

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Fit 3 divs on screen side by side 3 39
Creating a route in asp.net webforms 2 32
IEnumerable<T> to a List<T> 8 37
How to repeat the data 4 13
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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