login into a WEB page programatically.

HLRosenberger
HLRosenberger used Ask the Experts™
on
I'm logging into a WEB page programatically. Using HttpWebRequest, I am doing the following:

1) download the login WEB page.
2) Parse out the VIEWSTATE.
3) Create and encode post data.
4) POST it by writing to stream.

Here's my post data code:

 postData = String.Format(
                     "__VIEWSTATE={0}&Login1_UserName={1}&Login1_Password={2}&Login1_LoginButton=LOGIN",
                     viewState, username, password)

Now, I read an article about how to send the username and password. Login1_UserName and Login1_Password are the asp IDs of the textboxes for username and password, and Login1_LoginButton is the submit button.   Now upon post, I am getting back a page where there is a read asterisk next to the textboxes for username and password.  So, I must have submitted it correctly, but without the username and password.

Can anyone help me out? How do I send the username and password?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
There may be a hidden field in the form.

Author

Commented:
A hidden field that would do what?  be fed by the visible username or password?
I found the problem.  I used Fiddler to look at the traffic being sent.   It was sending
__EVENTTARGET
__EVENTARGUMENT
__VIEWSTATE
__EVENTVALIDATION

I was already extracting the ViewState, and I added extracting the __EVENTVALIDATION. Both __EVENTTARGET and __EVENTARGUMENT were empty, so I sent empty values.

And, I can now login.

Author

Commented:
This is the correct answer, and was tested.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial