0

I have old asp.net webform page which extract Title, Description & Images from any web page specified as URL using following code

HtmlDocument doc = new HtmlDocument();
            var url = txtGrabNewsURL.Text.Trim();

            string html;
            using (var wc = new GZipWebClient())
                html = wc.DownloadString(url);

            var htmldocObject = new HtmlDocument();
            htmldocObject.LoadHtml(html);


            var webGet = new HtmlWeb();
           // ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            
            doc = webGet.Load(url);
            var baseUrl = new Uri(url);
            //  doc.LoadHtml(response);


            String title = (from x in doc.DocumentNode.Descendants()
                            where x.Name.ToLower() == "title"
                            select x.InnerText).FirstOrDefault();

            String desc = (from x in doc.DocumentNode.Descendants()
                           where x.Name.ToLower() == "meta"
                           && x.Attributes["name"] != null
                           && x.Attributes["name"].Value.ToLower() == "description"
                           select x.Attributes["content"].Value).FirstOrDefault();

            String ogImage = (from x in doc.DocumentNode.Descendants()
                              where x.Name.ToLower() == "meta"
                              && x.Attributes["property"] != null
                              && x.Attributes["property"].Value.ToLower() == "og:image"
                              select x.Attributes["content"].Value).FirstOrDefault();


            List<String> imgs = (from x in doc.DocumentNode.Descendants()
                                 where x.Name.ToLower() == "img"
                                  && x.Attributes["src"] != null
                                 select x.Attributes["src"].Value).ToList<String>();

            List<String> imgList = (from x in doc.DocumentNode.Descendants("img")
                                    where x.Attributes["src"] != null
                                    select x.Attributes["src"].Value.ToLower()).ToList<String>();

 }
        catch (Exception ex)
        {
            lblMSG.Text = "MSG: " + ex.Message + "<br>ex.Source " + ex.Source;
        }

ERROR MESSAGE

MSG: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

I changes SecurityProtocolType.Tls11 code to Tls12, Tls13 but it doesnt seems to work. I cross checked website SSL certificate it is also fine as i am using cloudflare details SSL

I am not sure what else i can do or is there diffrent code that i cant try...

I have been looking for solution for last two days but nothing seems to work.

There has been no change on Server or code. This piece of code suddenly stopped word

This code was working fine two days back and since yesterday it stopped working as i keep getting error when i use this function

Learning
  • 19,469
  • 39
  • 180
  • 373

1 Answers1

0

There must something be changed with your certificate.

Please look an answer in this related question and see if it helps: https://stackoverflow.com/a/4492843/12479757

Check if certificate is still valid, it is installed on machine and system is up to date (certificate authority is still trusted).

mr_city
  • 1
  • 2
  • I did check SSL certificate all is OK as it passes test on different SSL test websites – Learning Aug 04 '22 at 07:18
  • You can try ideas from this similar post: [link](https://stackoverflow.com/questions/10822509/the-request-was-aborted-could-not-create-ssl-tls-secure-channel?rq=1) – mr_city Aug 04 '22 at 12:43