I am attempting to write a software application that will make an effort to login towards the Microsoft Online Admin website and report on their behavior whether it's obtainable.

Using code mainly out of this article, http://odetocode.com/articles/162.aspx plus some screen scraping I've pieced together the next. Regrettably it does not work, the ultimate response shows that i'm still searching in the login page as opposed to the target page.

Any help could be terrific. Thanks ahead of time.

    private void LoginToSite()

    Publish data

        string viewState = ExtractViewState(responseData)

        string postData =

              String.Format(

                 "__VIEWSTATE=&AdminCenterLoginControl$UserNameTextBox=&AdminCenterLoginControl$PasswordTextbox=&lifier__EVENTTARGET=AdminCenterLoginControl_ActionButton",

                 viewState, USERNAME, PASSWORD

              )

        // possess a cookie container prepared to get the forms auth cookie

        CookieContainer snacks = new CookieContainer()

        // now publish towards the login form

        webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest

        webRequest.Method = "Publish"

        webRequest.ContentType = "application/x-world wide web-form-urlencoded"

        webRequest.CookieContainer = snacks

        // write the shape values in to the request message

        StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream())

        requestWriter.Write(postData)

        requestWriter.Close()

        // we do not require the items in the response, only the cookie it issues

        webRequest.GetResponse().Close()

        // now we are able to send cookie together with a request the protected page

        webRequest = WebRequest.Create(TARGET_PAGE_URL) as HttpWebRequest

        webRequest.CookieContainer = snacks

        responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream())

        // and browse the response

        responseData = responseReader.ReadToEnd()

        responseReader.Close()

        MessageBox.Show(responseData)

    

    private string ExtractViewState(string s)

    

edit

    private void LoginToSite()

    Publish data

        string viewState = ExtractViewState(response1)

        string postData = String.Format(

                 "__VIEWSTATE=&AdminCenterLoginControl$UserNameTextBox=&AdminCenterLoginControl$PasswordTextbox=&lifier__EVENTTARGET=AdminCenterLoginControl_ActionButton",

                 viewState, USERNAME, PASSWORD)

        // Setup the Request qualities

        webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest

        webRequest.Method = "Publish"

        webRequest.ContentType = "application/x-world wide web-form-urlencoded"

        CookieContainer snacks = new CookieContainer()

        webRequest.CookieContainer = snacks

        // Publish to the shape

        using (StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()))

        

        // Read response

        string response2 = new StreamReader(webRequest.GetResponse().GetResponseStream()).ReadToEnd()

        MessageBox.Show(response2)