title: How to manitain session values during HttpWebRequest?
body: <p>In my <code>code</code> I'm sending a <code>HttpWebRequest</code> to a page in my website.</p>
  
  <p>When <code>request</code> sends to this page, It doesn't maintain the <code>Session</code> values.</p>
  
  <p><strong>Below is the code, from where I'm generating the web request:</strong></p>
  
  <pre><code>Public Overloads Shared Function ReadURL(ByVal sUrl As String) As String
          Dim sBody As String
          Dim oResponse As HttpWebResponse
          Dim oRequest As HttpWebRequest
          Dim oCookies As New CookieContainer
          oRequest = WebRequest.Create("http://localhost:64802/inventory/purchase_order.aspx?id=5654")
          oRequest.CookieContainer = oCookies
          oResponse = oRequest.GetResponse()
          Dim oReader As New StreamReader(oResponse.GetResponseStream())
          sBody = oReader.ReadToEnd
          oReader.Close()
          oResponse.Close()
          Return sBody
      End Function
  </code></pre>
  
  <p><strong>Below is the code written on Page_Load of Purchaseorder.aspx.vb:</strong></p>
  
  <pre><code>iDomains_ID = Session("Domains_ID")
          iLogin_ID = Session("Login_ID")
          sPage = Request.Path
          If Request.QueryString.Count &gt; 0 Then sPage &amp;= "?" &amp; Request.QueryString.ToString()
          sPage = shared01.Encrypt(sPage, Application("PK"))
  
          If Not User.Identity.IsAuthenticated Or iLogin_ID = 0 Then
              Response.Redirect("/login.aspx?page=" &amp; sPage)
              Exit Sub
          End If
  </code></pre>
  
  <p>Above <code>code</code> doesn't gets the <code>session</code> values and it redirects to the <code>login page</code>.</p>
  
  <p>So, how i can maintain the <code>session</code> on both pages during <code>HttpWebRequest</code>.</p>
  
  <p>Looking for your replies.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've tried to use <code>CookieContainer</code> class as you can see in above code. But it doesn't work at all.</p>