title: Cookie to Expire when Browser Session Ends
body: <p>My research indicates that, if I create a cookie and don't set the expiration date, it will expire when the browser is closed.</p>
  
  <p>So I created a cookie like this:</p>
  
  <pre><code>Response.Cookies.Set(new HttpCookie("MyKey", "X"));
  </code></pre>
  
  <p>But when I close the browser and then reopen it, the following expression equals true:</p>
  
  <pre><code>Request.Cookies["MyKey"] != null
  </code></pre>
  
  <p>How can I have the cookie expire when the browser session ends?</p>
  
  <p><em>Note: For my purposes, using static data instead of a cookie seems ideal. But my understanding is that an ASP.NET can restart for a variety of reasons, and that could pull the rug out from under the current user if I lost this setting.</em></p>