0

I was trying to persist a logged in user as a cookie through a WCF Rest Service. I setup the cookie like follows, through a component that the WCF rest service uses:

var cookie = new HttpCookie("Key");
.
.
cookie.HttpOnly = true;

HttpContext.Current.Response.Cookies.Add(cookie);

But the cookie, when retrieved, later on is null:

HttpContext.Current.Request.Cookies.Get("Key"); //returns null

Is cookie not a good way of doing this for WCF rest services, or is there another way to do it?

EDIT: I should note I'm using the same component for a web site, and it's working great for it.

Thanks.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Can you provide more context around where this code? Is this inside WCF service method? Why are you persisting he logged in user? – Petar Vučetin Apr 17 '12 at 02:59
  • @PetarVucetin Yes, I have a component inside the WCF rest service. I need a user to first login, and a lot of the REST method are related to the logged in user, and only return that user's information. – Brian Mains Apr 17 '12 at 11:17

1 Answers1

1

My best guess is that you need to have [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] attribute on your service to access the HttpContext MSDN details

Petar Vučetin
  • 3,555
  • 2
  • 22
  • 31