R
rlueneberg
I am trying to foward the old sessionID using "Session.SessionID" to
an HttpWebRequest CookieContainer so that I can capture the requested
page session variables but it is not working as it is supposed to. The
HttpResponse object always returns a different sessionID from the old
one which I am trying to force. Why is objRequest not carrying over the
old SessionID?
private String ReadHtmlPage(string url)
{
String result = string.Empty;
CookieContainer myContainer = new CookieContainer();
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "GET";
objRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT5.0; .NET CLR 1.0.2914)";
objRequest.CookieContainer = new CookieContainer();
Cookie c = new Cookie();
c.Name = "ASP.NET_SessionId";
c.Value = Session.SessionID;
c.Domain = "http://localhost/mysite/";
myContainer.Add(c);
Response.Write("OLD SessionID -> " + Session.SessionID +
"<br>");
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
//retain the cookies
foreach (Cookie cook in objResponse.Cookies)
{
Response.Write("New SessionID -> " + cook.Name +
cook.Value + cook.Domain + "<br>");
}
//Check out the html.
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream())
)
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Thanks
Rod
an HttpWebRequest CookieContainer so that I can capture the requested
page session variables but it is not working as it is supposed to. The
HttpResponse object always returns a different sessionID from the old
one which I am trying to force. Why is objRequest not carrying over the
old SessionID?
private String ReadHtmlPage(string url)
{
String result = string.Empty;
CookieContainer myContainer = new CookieContainer();
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "GET";
objRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT5.0; .NET CLR 1.0.2914)";
objRequest.CookieContainer = new CookieContainer();
Cookie c = new Cookie();
c.Name = "ASP.NET_SessionId";
c.Value = Session.SessionID;
c.Domain = "http://localhost/mysite/";
myContainer.Add(c);
Response.Write("OLD SessionID -> " + Session.SessionID +
"<br>");
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
//retain the cookies
foreach (Cookie cook in objResponse.Cookies)
{
Response.Write("New SessionID -> " + cook.Name +
cook.Value + cook.Domain + "<br>");
}
//Check out the html.
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream())
)
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
Thanks
Rod