Solved

wcf, cookie

Posted on 2013-11-18
6
486 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dynamic menu in asp.net c# 11 57
Why don't I see this table in EDMX file? 2 23
LINQ - C# to VB convertion 12 46
Run time Error 4 34
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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now