arjunan Selvam

arjunan Selvam

  • 2.1k
  • 3
  • 1.2k

cookies are not storing when calling from webapi

Jan 8 2014 9:03 PM
i am calling one of the rest services using webapi.It will send the response as cookies.I want to reuse the cookies for further requests.I don't have any problem to use the cookies for subsequent calls.I tested everything in the restclient where i can see the cookies.but i tried to call the services using Jquery ajax and i noticed one thing like the cookies whatever i am sending in the response header is not getting stored in the browser.I tried in all the browser.I want to save cookies in the browser.I have shared the code what i am using below.
 
 
CookieHeaderValue ch;
List<CookieHeaderValue> cookieList = new List<CookieHeaderValue>();
if (cookieStore != null)
{
if (resp.Headers.Get("ETag") != null)
{
foreach (Cookie ck in cookieStore.GetCookies(GetRequest.RequestUri))
{
ch = new CookieHeaderValue(ck.Name, ck.Value);
ch.Path = "/";
cookieList.Add(ch);
}
ch = new CookieHeaderValue("ETag", resp.Headers.Get("ETag"));
ch.Path = "/";
cookieList.Add(ch);
}
result = sourceRequest.CreateResponse(resp.StatusCode);
result.Content = new StringContent(resultData, Encoding.UTF8, responseFormat);
result.Headers.AddCookies(cookieList);
 
I tried the same in google.most of them mentioned like it might be domain issue.I am not calling from the mylocal.I want to store cookies in the browser. 

Answers (1)