Padmanathan J
Padmanathan J

Reputation: 4620

ASP.net C# web-browser Control always open ie browser only?

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();

    } 

Upvotes: 0

Views: 993

Answers (1)

EyeSeeSharp
EyeSeeSharp

Reputation: 645

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.

Upvotes: 1

Related Questions