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