My current goal is to be able to get the HTML source of an ASP.Net page that is hosted locally. Even though I make sure the session id is stored in the cookie container of the HttpWebRequest the Session info does not exist on the requested page (I'm stepping through it on debug and it's Session.Session ID does not equal the ID i'm sending). This causes me to lose the login status and eventually causes an error.
My first question: Is there a way to do a local (loopback) request that follows the same idea of HttpWebRequest that uses your current session information, so I can avoid sending cookies all together?
If not, then what else can be done to ensure sending the session id to use through cookies works?
My first question: Is there a way to do a local (loopback) request that follows the same idea of HttpWebRequest that uses your current session information, so I can avoid sending cookies all together?
If not, then what else can be done to ensure sending the session id to use through cookies works?
Code:
Uri site = new Uri(uri); //uri contains the url i'm hitting locally HttpCookieCollection currentCookies = HttpContext.Current.Request.Cookies; HttpWebRequest wReq = (HttpWebRequest) WebRequest.Create(site); wReq.CookieContainer = new CookieContainer(); //Cookie[0] is the only 1 and its the sessionid Cookie sessionCookie = new Cookie(HttpContext.Current.Request.Cookies[0].Name, Session.SessionID, "/", baseURL); wReq.CookieContainer.Add(sessionCookie); WebResponse wResp = wReq.GetResponse(); Stream respStream = wResp.GetResponseStream(); StreamReader httpreader = new StreamReader(respStream, Encoding.ASCII);