C #. NET application for Automatic Webpage Login

Source: Internet
Author: User

Compile a Windows form application in C #ProgramTo automatically log on to a specific page.

The following uses automatic login: http://bm.chinaz.com/Web/Login.aspx as an example, explains how to simulate manually enter the user name and password and click Login, to achieve automatic login.

Create a new C # application, give the application a name, such as autologin, add a Textbox, button, and webbrowser control to the form, and add a webbrowser1_documentcompleted event to the webbrowser control.

Click Event of the button andCodeAs follows:

Private void btn_add_click (Object sender, eventargs e) {string Surl = txb_url.text.trim (); If (Surl. length> 0) {webbrowser1.navigate (Surl) ;}} private void webbrowserappsdocumentcompleted (Object sender, webbrowserdocumentcompletedeventargs e) {htmlelement clickbtn = NULL; If (E. URL. tostring (). tolower (). indexof ("login. aspx ")> 0) {htmldocument Doc = webbrowser1.document; For (INT I = 0; I <Doc. all. count; I ++) {If (Doc. all [I]. tagname. toupper (). equals ("input") {Switch (Doc. all [I]. name) {Case "txtusername": Doc. all [I]. innertext = "xxxx@yy.com"; // user name break; Case "txtpassword": Doc. all [I]. innertext = "zzzzzzzz"; // password break; Case "btnsubmit": clickbtn = Doc. all [I]; break ;}} clickbtn. invokemember ("click"); // click the "Log on" button }}

when you enter the http://bm.chinaz.com/Web/Login.aspx In the textbox and click the button, you can achieve automatic login page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.