title: Parsing cookies
body: <p>I have a self-hosted WCF service with an endpoint set up with WebHttpBinding listening for HTTP requests. I need to access cookies passed with these requests. I can get the <code>Cookie:</code> header value, but I am stuck with actual parsing. My implementation attempt was using <code>CookieContainer</code>:</p>
  <pre><code>var container = new CookieContainer();
  var uri = new Uri(&quot;http://localhost/&quot;);
  container.SetCookies(uri, cookieHeader);
  var cookies = container.GetCookies(uri).OfType&lt;Cookie&gt;();
  foreach (var cookie in cookies)
  {
      Console.WriteLine(&quot;{0} = {1}&quot;, cookie.Name, cookie.Value);
  }
  </code></pre>
  <p>Issue with this code is that <code>CookieContainer</code> expects cookies to be separated by comma (<code>cookieHeader=&quot;c1=v1,c2=v2&quot;</code>), while browsers tend to use semicolon (<code>cookieHeader=&quot;c1=v1;c2=v2&quot;</code>) for that. Since <a href="https://www.rfc-editor.org/rfc/rfc6265#section-4.2.1" rel="nofollow noreferrer">RFC 6265</a> permits only semicolon to be used as separator (older RFC's permit both, though) I am a bit puzzled why <code>CookieContainer</code> only supports comma. Now I am struggling for finding an alternative solution for the problem that seems to be quite typical. How do I parse cookies properly? ASP.NET should be able to do it, does it expose any publicly usable classes for that?</p>