Asp.Net c# logging in to another website
<p>I know this question has been asked quite a lot of times which is how I have got to where I am at with the code below however I just can't get it to work on the particular website I am trying to access. At the site I am trying to access I need to retrieve certain values from the page however things like price and availability only come up after logging in so I am trying to submit my login information and then go to the product page to get the information I need using HTML Agility Pack.</p>

<p>At the moment it seems to attempt the login however the website is either not accepting it or the cookies are not present on the next page load to actually keep me logged in.</p>

<p>If someone could help me with this I would be very grateful as I am not a programmer but have been assigned this task as part of a software installation.</p>

<pre><code>protected void Button5_Click(object sender, System.EventArgs e)
{
    string LOGIN_URL = "http://www.videor.com/quicklogin/1/0/0/0/index.html";
    string SECRET_PAGE_URL = "http://www.videor.com/item/47/32/0/703/index.html?scriptMode=&amp;CUSTOMERNO=xxx&amp;USERNAME=xxx&amp;activeTabId=0";

    // have a cookie container ready to receive the forms auth cookie
    CookieContainer cookies = new CookieContainer();

    // first, request the login form to get the viewstate value
    HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
    webRequest.CookieContainer = cookies;
    StreamReader responseReader = new StreamReader(
          webRequest.GetResponse().GetResponseStream()
       );
    string responseData = responseReader.ReadToEnd();
    responseReader.Close();

    string postData = "CUSTOMERNO=xxxx&amp;USERNAME=xxxxx&amp;PASSWORD=xxxxx";

    // now post to the login form
    webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.CookieContainer = cookies;

    // write the form values into the request message
    StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
    requestWriter.Write(postData);
    requestWriter.Close();

    // we don't need the contents of the response, just the cookie it issues
    webRequest.GetResponse().Close();

    // now we can send out cookie along with a request for the protected page
    webRequest = WebRequest.Create(SECRET_PAGE_URL) as HttpWebRequest;
    webRequest.CookieContainer = cookies;
    responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());

    // and read the response
    responseData = responseReader.ReadToEnd();
    responseReader.Close();

    Response.Write(responseData);
}
</code></pre>
