Skip to content

Instantly share code, notes, and snippets.

@sclarson
Created April 9, 2012 16:14
Show Gist options
  • Save sclarson/2344489 to your computer and use it in GitHub Desktop.
Save sclarson/2344489 to your computer and use it in GitHub Desktop.
Some pages don't have a title set in GSA data. This is a slowwww work around while that is remedied.
this.PageName = node.SelectSingleNode("T") != null ? EPiServer.Core.Html.TextIndexer.StripHtml(node.SelectSingleNode("T").InnerXml.Trim().HtmlDecode(),200) : string.Empty;
if (this.PageName.IsNullOrWhiteSpace())
{
this.PageName = "( No Title )";
var UseWebRequestToResolveSupportTitle =
WebConfigurationManager.AppSettings["UseWebRequestToResolveSupportTitle"] != null && Convert.ToBoolean(WebConfigurationManager.AppSettings["UseWebRequestToResolveSupportTitle"]);
if (UseWebRequestToResolveSupportTitle)
{
var cachedTitle =
(string)EPiServer.CacheManager.Get(SupportCacheKey);
if (string.IsNullOrEmpty(cachedTitle))
{
// Make the WebClient we'll be using able to handle support's bad cert
var sslFailureCallback = new RemoteCertificateValidationCallback(delegate { return true; });
ServicePointManager.ServerCertificateValidationCallback += sslFailureCallback;
var client = new WebClient();
var html = client.DownloadString(this.PageURL);
// Retrieve just the title
var title = Regex.Match(html, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
EPiServer.CacheManager.Add(SupportCacheKey,title);
cachedTitle = title;
}
this.PageName = cachedTitle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment