title: How do I retrieve a cookie sent by the browser?
body: <p>I expect the browser to send a cookie with a given name. How do I read this cookie?</p>
  <p>I'm trying to read the docs: <a href="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/http-cookies#example-set-and-retrieve-cookies-in-a-message-handler" rel="nofollow noreferrer">Example: Set and Retrieve Cookies in a Message Handler</a>, <a href="https://docs.microsoft.com/en-us/previous-versions/aspnet/hh995249(v=vs.118)#httprequestheadersextensionsgetcookies-method-httprequestheadersstring" rel="nofollow noreferrer"><code>HttpRequestHeadersExtensions.GetCookies</code> Method <code>(HttpRequestHeaders, String)</code></a>, <a href="https://docs.microsoft.com/en-us/previous-versions/aspnet/hh944846(v=vs.108)" rel="nofollow noreferrer"><code>CookieHeaderValue</code> Class</a></p>
  <p>But unfortunately these docs make little sense to me :(</p>
  <p>First: They provided such an example of a code that retrieves a cookie (edited for brevity):</p>
  <pre class="lang-cs prettyprint-override"><code>var cookie = request.Headers.GetCookies(SessionIdToken).FirstOrDefault();
  sessionId = cookie[SessionIdToken].Value;
  </code></pre>
  <p>But <code>GetCookies</code> returns a <code>Collection&lt;CookieHeaderValue&gt;</code>, meaning that <code>cookie</code> in the above example should be of type <code>CookieHeaderValue</code>, which as per the docs I linked to does not have the <code>[]</code> property, so what does <code>cookie[SessionIdToken]</code> mean?</p>
  <p>Then: What does <code>GetCookies</code> actually do?</p>
  <p>As per the docs:</p>
  <blockquote>
  <p>Gets any cookie headers present in the request that contain a cookie state whose name that matches the specified value.</p>
  </blockquote>
  <p>I don't understand this description :(</p>
  <p>Why does it <em>get any cookie headers that contain a cookie state</em>? What is a <em>cookie state</em>? In my mental model a cookie is a small piece of data that has a name and meta parameters such as expiration date.</p>
  <p>Why does it get cookie headers present in the request that contain a cookie state <em>whose name matches the specified value</em>? What does the word <em>matches</em> here mean and how is it different from <em>whose name <strong>is equal to</strong> the specified value</em>? The word <em>matches</em> brings regular expressions to my mind but it does not seem that regexps is what this method accepts.</p>
  <p>All I want is to retrieve the value of a cookie by its name. Is it possible? And how?</p>
  <p>Note that I'm still stuck with .Net Framework rather than .Net Core, although this is supposed to be changed soon.</p>
  <p>Thank you for your time!</p>