title: Is it possible to set a cookie during a redirect in ASP.NET?
body: <p>I am using ASP.NET.  I either add or set a cookie (depending on whether the <code>HttpRequest</code> contains a cookie with specified key), and immediately afterward call <code>Response.Redirect</code>.  The cookie is not set.  Is this correct behavior?  Is there something mutually exclusive about setting a cookie during an http response with a 302 status code?   </p>
  
  <h2>Here's the source:</h2>
  
  <pre><code>        if (context.HttpContext.Request.Browser.Cookies)
          {
              var cookies = context.HttpContext.Request.Cookies;
              var stateCookie = new HttpCookie(SR.session, clientState.SessionId.ToString());
              if (cookies.AllKeys.Contains(SR.session))
              {
                  context.HttpContext.Response.Cookies.Set(stateCookie);
              }
              else
              {
                  context.HttpContext.Response.Cookies.Add(stateCookie);
              }
          }
  </code></pre>
  
  <h2>Here are the Response headers</h2>
  
  <ul>
  <li>X-AspNetMvc-Version - 2.0</li>
  <li>Connection - Close</li>
  <li>Cache-Control - private</li>
  <li>Content-Type - text/html</li>
  <li>Date - Sun, 20 Mar 2011 03:48:04 GMT</li>
  <li>Location - <a href="http://localhost:3599/Home/Redirected">http://localhost:3599/Home/Redirected</a></li>
  <li>Server - ASP.NET Development Server/9.0.0.0</li>
  <li>X-AspNet-Version - 2.0.50727</li>
  </ul>