When I set a session value then redirect to another page I am able to retrieve the session value. As follows:
test-set.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Session("test") = "hello world!"
Response.Redirect("test-get.aspx")
End Sub
test-get.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write("test = " & CType(Session("test"), String))
End Sub
The above results:
test = hello world!
However, when trying this via a HTTPWebRequest a new session is created for the redirected page.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TestRequest As Net.HttpWebRequest = CType(System.Net.WebRequest.Create(Me.Request.Url.GetLeftPart(UriPartial.Authority) & "/test-set.aspx"), Net.HttpWebRequest)
TestRequest.Method = "GET"
Using TestResponse As Net.HttpWebResponse = CType(TestRequest.GetResponse, Net.HttpWebResponse)
Using Reader As IO.StreamReader = New IO.StreamReader(TestResponse.GetResponseStream)
Response.Write(Reader.ReadToEnd)
End Using
End Using
End Sub
Using HTTPWebRequest results as:
test =
So the HTTPWebRequest retrieve the output from the redirected page but the redirected page is opened in a new session.
How can I open the redirected page in the same session it was redirected from?
What I have tried:
HttpWebRequest.AllowAutoRedirect
HttpWebRequest.MaximumAutomaticRedirections
HttpWebRequest.KeepAlive
HttpWebRequest.UseDefaultCredentials
Response.Redirect("test-get.aspx, True")
Response.Redirect("test-get.aspx, False")