title: Reusing session cookie in HttpClient calls
body: <p>I have a Web API 2 project using cookie-based sessions for our internal use. I have <code>/api/login</code> and <code>/api/logout</code> actions created and it works fine using a browser to access it.</p>
  
  <p>I'm now trying to create a C# client to communicate with the API by using <code>HttpClient</code>. I can log in fine using:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Uri loginUri =  new Uri("http://localhost/api", "login");
  HttpResponseMessage response = _http.PostAsJsonAsync(loginUri, loginModel).Result;
  </code></pre>
  
  <p>And I can get the session id string from the cookie by</p>
  
  <pre class="lang-cs prettyprint-override"><code>var cookies = _httpHandler.CookieContainer.GetCookies(uri);
  if (cookies["session_id"] != null)
      sessionID = cookies["session_id"].Value;
  </code></pre>
  
  <p><strong>My question is</strong>: for every subsequent request including the logout request, how do I include the <code>session_id</code> cookie in the request header? I would like to reuse the <code>HttpClient</code> object for the duration of the session if possible. I saw <a href="https://stackoverflow.com/questions/13041354/how-to-generalize-login-action-and-logout-when-using-web-api-httpclient">this question and answer</a>, but it's for calling login, performing the operation, and logout in the same request. </p>
  
  <p>Thanks!</p>