title: HttpWebRequest - ASP .NET MVC 3 Passing Session State
body: <p>I need to acquire HTML markup of a controller/action in order to generate PDF. What I have done is:</p>
  
  <pre><code>    public ActionResult Index()
      {
          Session["Message"] = "SESSION-MESSAGE";
  
          String URL = "http://localhost:7401/Home/SuperComplex";
  
          HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
          req.CookieContainer = new CookieContainer();
  
          for (int i = 0; i &lt;= this.Request.Cookies.Count - 1; i++)
              req.CookieContainer.Add(
                  new System.Net.Cookie(
                      name: this.Request.Cookies[i].Name,
                      value: Request.Cookies[i].Value,
                      path: Request.Cookies[i].Path, domain: this.HttpContext.Request.Url.Host)
                  );
  
          using (var r = req.GetResponse())
          {
              using (var s = new StreamReader(r.GetResponseStream()))
              {
                  var htmlToPrint = s.ReadToEnd();
                  Response.Write("&lt;h1&gt;" + htmlToPrint + "&lt;/h1&gt;");
              }
          }
  
          return View();
      }
  </code></pre>
  
  <p>Considering above said situation, in SuperComplex session, I should have the Session["Message"]. But for some strange reason, it does not go there.</p>
  
  <p>I have checked Session.SessionId - in both cases it is same.</p>
  
  <p>Also, on second or third request, request timesout!</p>
  
  <p>Again: <a href="http://localhost:7401/(S(SESSION_ID))/Home/About" rel="nofollow">http://localhost:7401/(S(SESSION_ID))/Home/About</a></p>
  
  <p>If requested in other browser: session hijack does happen - but WebRequest dies! :(</p>
  
  <p>Help - anyone?</p>