In Asp.net C#
, Using web-browser Control , I need to Implement Auto-Login In live websites, Its works only in Internet Explorer(IE)
and Doesn't works in Firefox and Chrome and other browsers . How to solve this
Here is my C#
Code
void capture()
{
Thread thread = new Thread(delegate()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
browser.Navigate("My URL");
browser.Width = 1024;
browser.ScriptErrorsSuppressed = true;
browser.Height = 768;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser browser1 = sender as WebBrowser;
HtmlDocument doc = browser1.Document;
string user = txtUsername.Text.Trim();
string pass = password;
doc.GetElementById("Your userID").SetAttribute("value", user);
doc.GetElementById("Your Password").SetAttribute("value", pass);
//get Button on page and fire its click event
doc.GetElementById("Your Buttonid").InvokeMember("Click");
Thread thread = new Thread(delegate()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.AllowNavigation = true;
browser.Navigate("My URL");
browser.Width = 1024;
browser.Height = 768;
browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted1);
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
Well, you're using the WebBrowser control which is built around the IE engine. You'll have to use something else to get another browser. Check out something like Awesomium.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.