Thanks for responses! Sorry I got my question wrong so I am rephrasing my question as below:
I need to read some text values from one of our old aspx pages of one internal website.
When I directly put url in a newly opened browser, first time, it got re-directed to default page, I need to click on a link to get the the page I wanted; then I put in the same url in the same browser window and hit Enter again, it goes to correct page and everything looks good. I think the second time works because there are some session variable established.
How can I achieve this from code? When I use following code trying to read that page (webReq.GetResponse()), I can see from Fiddler that it first hit the page I wanted, then it got redirected to the default.aspx of that site - exactly like if I do it manually first time with new browser window.
Here is the code, I have tried call webReq.GetResponse() second time but Fiddler doesn't show any traffic for my second call. Any suggestions? - Thanks!
string url = "http://mycompany.com/page1.aspx";
HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(url);
try
{
webReq.CookieContainer = new CookieContainer();
webReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko";
webReq.Method = "GET";
webReq.Credentials = CredentialCache.DefaultCredentials;
using (WebResponse response = webReq.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
string res = reader.ReadToEnd();
...
}
}
}
catch (Exception ex)
{
...
}