Click here to Skip to main content
13,256,123 members (41,186 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi, my asp.net code working fine local but i am hosting this project not show data
please help me..

MY CODE IS -:

private void CallBatocTransIndia()
        {
 
            string url = "http://www.xxxx.in/";
            
            Thread thread = new Thread(delegate()
            {
                using (WebBrowser browser = new WebBrowser())
                {
                    browser.ScrollBarsEnabled = false;
                    browser.AllowNavigation = true;
                    browser.Navigate(url);
                    browser.Width = 1024;
                    browser.Height = 768;
                    //browser.Document.GetElementById("txtLrNo").SetAttribute("value", "15470038610");
                    //browser.Document.GetElementById("ImageButton1").InvokeMember("click");
                    browser.ScriptErrorsSuppressed = true;
 
                    browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
                    browser.ProgressChanged += new WebBrowserProgressChangedEventHandler(ProgressChanged);
                    while (browser.ReadyState != WebBrowserReadyState.Complete)
                    {
 
                        System.Windows.Forms.Application.DoEvents();
 
                        //gg.InnerHtml = browser.Document.Body.InnerHtml;
                    }
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
 

        }
 
        long ff = 0;
        private void ProgressChanged(Object sender, WebBrowserProgressChangedEventArgs e)
        {
            try
            {
                Thread.Sleep(3000);
                HtmlDocument doc = ((WebBrowser)sender).Document;
                if (e.MaximumProgress == 10000)
                {
                    ff = e.MaximumProgress;
                }
                if (e.CurrentProgress > e.MaximumProgress)
                {
                    if (e.CurrentProgress == 10000)
                    {
                        //string m1 = doc.Body.OuterHtml;
                        ////string m2 = GG.InnerHtml;
                        ////string m3 = GG.InnerHtml;
                        //int indexF = m1.IndexOf("LDM Details");
                        //int f = (m1.Length - indexF);
                        //string m11 = m1.Remove(indexF, f);
                        //gg.InnerHtml = m1;
                        //string varstr = doc.Body.OuterHtml;
                        //int indexf = varstr.IndexOf("Transit Details");
                        //int indexE = varstr.IndexOf("Top");
                        //gg.InnerHtml = doc.Body.OuterHtml;
                    }
 
                }
            }
            catch(Exception ex)
            {
                // browser.Navigate(txtUrl.Text.Trim());
                return;
            }
        }
 

        private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            string Lrno;
           // Response.Write("<script>alert('Hello');</script>");
            Lrno = Request.QueryString["Lrnostr"];
            try
            {
                HtmlDocument doc = ((WebBrowser)sender).Document;
                string g = e.Url.ToString();
 

                if (g == "http://www.xyz.in/")
                {
 
                    doc.GetElementById("txtLrNo").SetAttribute("value", "154700" + Lrno);
                    doc.GetElementById("ImageButton1").InvokeMember("click");
                    flag = true;
                    //System.Threading.Thread.Sleep(20000);
 
                }
                else
                {
                    //Response.Write("<script>alert('Hello In');</script>");
 
                    string varstr = doc.Body.OuterHtml;
                    int indexf = varstr.IndexOf("Transit Details");
                    int indexE = varstr.IndexOf("Top");
 
                    string Main = "<table>" + doc.Body.OuterHtml.ToString().Substring(indexf, (indexE - indexf)) + "</table>";
                    //int indexEtr = Main.IndexOf("LDM Details");
                    int indexEtr = Main.IndexOf("</TABLE>");
 
                    string TrDt = Main.Substring(0, (Main.Length - indexEtr));
                    string LdmDt = Main.Substring(indexEtr, (Main.Length - indexEtr));
                    int indexCashdt = LdmDt.IndexOf("Cash Memo Details");
                    string LdmDt1 = LdmDt.Substring(0, (indexCashdt));
 
                    BTPLTrans.InnerHtml = Main; // "<table>" + TrDt + "</Table>" + "<table>" + LdmDt1 + "</table>";
                }
 

            }
            catch
            {
               // browser.Navigate(txtUrl.Text.Trim());
                return;
            }
 
       
        }


What I have tried:

Not show data in hosting server
Posted 10-Nov-17 1:20am
Updated 10-Nov-17 18:36pm
v2
Comments
Suvendu Shekhar Giri 10-Nov-17 6:30am
   
Well, what error are you getting?
Have you enabled error logging/tracing/anything?
Priyam2012 10-Nov-17 8:26am
   
not show any error...
F-ES Sitecore 10-Nov-17 7:03am
   
Code like this rarely works on asp.net, it only worked on your local machine probably because you were using your own account to run your code, it wasn't in a multi-user environment, or a million other factors. If you're determined to unethically use a third party website and present it as if it is your own work then you'll need to learn another way of doing it that will work from asp.net code.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This code will not work in an ASP.NET application. The WebBrowser control MUST be used in a Windows Forms app WITH A WINDOW!

I'm sure you got it to work on your machine because the code was running as YOU when you debugged it in Visual Studio. It will NOT work when deployed to a web server where the code will never have a window and is running as a service account.

You have to scrap this code and rewrite it using some other method to "scrap" the website you're trying to get data from. Perhaps the WebRequest and HttpWebRequest class would work for you. I suggest Google for those and start reading to find out how to use them.
  Permalink  
Comments
Priyam2012 10-Nov-17 13:51pm
   
Thanks for reply
ok instoll visual stdio in my VPN server then code work ?
Dave Kreskowiak 10-Nov-17 14:06pm
   
What the hell does that have to do with anything?

No! The code will NEVER WORK in a hosted ASP.NET application!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100