Posting to Social Media shows a different <TITLE>

Topics: ASP.NET 2.0, Business Logic Layer, Themes
Jul 8, 2014 at 3:28 AM
Hi,

Since upgrading to Blog Engine 2.9, why is it that when I post an update to some websites (i.e., LinkedIn), I see the following highlighted text attached as the title of the post? I have tried searching the contents of the files in Blog Engine and have found nothing to correlate this.

Is there somewhere I can remove this?

For instance I might have a blog posting that says - "This is my Blog" - but the posting shows up as "This is my Blog | Sandro Ego Website".

Can I turn this off?

Thank you - Greg
Coordinator
Jul 8, 2014 at 4:34 AM
Basic settings, turn off "Use blog name in page titles ".
Jul 8, 2014 at 6:00 PM
Edited Jul 8, 2014 at 6:00 PM
That did not work... however when I look at the generated source code for that particular page I see this content being generated which is leading to why this is being done.

How do I turn this off? My RSS feeds are set to RSS 2.0 not ATOM 1.0

See the output below... I want all the Sandro Ego entries removed... but there doesn't seem a way to do so...

<link type="application/rss+xml" rel="alternate" title="We are Lync MVP (RSS)" href="/post/feed/2014/07/01/we-are-lync-mvp?format=ATOM" />
<link type="application/rss+xml" rel="alternate" title="We are Lync MVP (ATOM)" href="/post/feed/2014/07/01/we-are-lync-mvp?format=ATOM" /><meta property="og:title" content="We are Lync MVP | Sandro Ego Website" /><meta property="og:description" content="Well what a weekend of news and events...I try to do a lot of blogging, some months more than others" /><meta property="og:url" content="http://lync.openjive.com/post/2014/07/01/we-are-lync-mvp" /><meta property="article:author" content="greg" /><meta property="og:image" content="http://lync.openjive.com" /><meta itemprop="name" content="We are Lync MVP" /><meta itemprop="description" content="Well what a weekend of news and events...I try to do a lot of blogging, some months more than others" /><meta itemprop="url" content="http://lync.openjive.com/post/2014/07/01/we-are-lync-mvp" /><meta itemprop="author" content="greg" /><meta property="image" content="http://lync.openjive.com" /><meta name="twitter:card" content="summary" /><meta name="twitter:title" content="We are Lync MVP | Sandro Ego Website" /><meta name="twitter:site" content="@sandroego" /><meta name="twitter:creator" content="@sandroego" /><meta name="twitter:url" content="http://lync.openjive.com/post/2014/07/01/we-are-lync-mvp" /><meta name="twitter:description" content="Well what a weekend of news and events...I try to do a lot of blogging, some months more than others" /><meta name="twitter:image" content="http://lync.openjive.com" />
Coordinator
Jul 8, 2014 at 8:01 PM
The "twitter:title" is not part of BlogEngine. Could be added by theme or extension. Also not sure how you update to LinkedIn, probably something custom too?
Jul 9, 2014 at 5:36 AM
Sorry for that inconvenience, I made that extension for a friend of mine but I did not noticed that mistake.

So, If you can, open with Visual Studio or WebMatrix the TwitterCard.cs file under App_Code/Extensions folder, find approximately row 42,43,44 and 68,69,70 and change information to your site name and twitter account.

Or if you want, this is the new code, updated, for TwitterCard.cs
/************************************************************************************/
// Created by :  IlDrago.com
// Website    :  http://ildrago.com
// Author     :  Alessio
/************************************************************************************/
using System;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
using System.Linq;
using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core.Web.Extensions;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;

/// <summary>
/// Summary description for TwitterCard
/// </summary>
[Extension("Adds an open group tag to first image in your post for Twitter identification. Twitter and other sites will show this image as a thumbnail when shared on their platform", "1.0", "<a href=\"http://am22tech.com\">Am22tech.com</a>")]
public class TwitterCard
{
    /// <summary>
    /// static constructor to init the settings
    /// </summary>
    private const string ExtensionName = "TwitterCard";
    static protected ExtensionSettings _settings = null;

    static protected string Key
    {
        get
        {
            return _settings.GetSingleValue("twitterID");
        }
    }

    public TwitterCard()
    {
        BlogEngine.Core.Post.Serving += AddTWImageThumbnail;
        BlogEngine.Core.Page.Serving += AddTWImageThumbnail;

        ExtensionSettings settings = new ExtensionSettings(ExtensionName);
        settings.AddParameter("twitterID", "Twitter User ID", 20, true);
        settings.AddValue("twitterID", "@you-user-name");
        settings.IsScalar = true;

        _settings = ExtensionManager.InitSettings(ExtensionName, settings);
    }

    /// <summary>
    /// On Post Served event handler will post to twitter
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void AddTWImageThumbnail(object sender, ServingEventArgs e)
    {
        if (e.Location == ServingLocation.SinglePage)
        {
            BlogEngine.Core.Page p = (BlogEngine.Core.Page)sender;
            AddMetaData("twitter:card", "summary");
            AddMetaData("twitter:title", p.Title + " | " + BlogSettings.Instance.Name);
            AddMetaData("twitter:site", Key);
            AddMetaData("twitter:creator", Key);
            AddMetaData("twitter:url", p.AbsoluteLink.AbsoluteUri.ToLower());
            AddMetaData("twitter:description", p.Description);
            string imgPath = string.Empty;
            HttpContext context = HttpContext.Current;

            if (context.CurrentHandler is System.Web.UI.Page)
            {
                System.Web.UI.Page page = (System.Web.UI.Page)context.CurrentHandler;
                imgPath = getImage(true, p.Content);

                if (!imgPath.ToLower().Contains("http://"))
                {
                    imgPath = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + imgPath;
                }

                AddHeader(page, imgPath);
            }
        }

        if (e.Location == ServingLocation.SinglePost)
        {
            Post p = (Post)sender;
            AddMetaData("twitter:card", "summary");
            AddMetaData("twitter:title", p.Title + " | " + BlogSettings.Instance.Name);
            AddMetaData("twitter:site", Key);
            AddMetaData("twitter:creator", Key);
            AddMetaData("twitter:url", p.AbsoluteLink.AbsoluteUri.ToLower());
            AddMetaData("twitter:description", p.Description);

            string imgPath = string.Empty;
            HttpContext context = HttpContext.Current;

            if (context.CurrentHandler is System.Web.UI.Page)
            {
                System.Web.UI.Page page = (System.Web.UI.Page)context.CurrentHandler;
                imgPath = getImage(true, p.Content);

                if (!imgPath.ToLower().Contains("http://"))
                {
                    imgPath = context.Request.Url.Scheme + "://" + context.Request.Url.Authority + imgPath;
                }

                AddHeader(page, imgPath);
            }
        }
    }

    private void AddHeader(System.Web.UI.Page page, string imgPath)
    {
        //Add meta tag for an appropriate image for google - Start   
        // FULL path(URL) of the image on site should be specified, relative path won't work. 
        
        HtmlMeta metaTagImgForTwitter = new HtmlMeta(); 
        metaTagImgForTwitter.Attributes.Add("name", "twitter:image");
        metaTagImgForTwitter.Attributes.Add("content", imgPath); 
        page.Header.Controls.Add(metaTagImgForTwitter);   
               
        //Add meta tag for an appropriate image for twitter -End 

    }
    private static void AddMetaData(string propertyName, string content)
    {
        if (string.IsNullOrEmpty(propertyName) || string.IsNullOrEmpty(content))
            return;
        if (HttpContext.Current.CurrentHandler is System.Web.UI.Page)
        {
            System.Web.UI.Page pg = (System.Web.UI.Page)HttpContext.Current.CurrentHandler;
            HtmlMeta metatag = new HtmlMeta();
            metatag.Attributes.Add("name", propertyName);
            metatag.Attributes.Add("content", content);
            pg.Header.Controls.Add(metatag);
        }
    }

    public string getImage(bool ShowExcerpt, string input) 
    { 
        if (!ShowExcerpt || input == null)
            return string.Empty; 
        string pain = input; 
        string pattern = @"<img(.|\n)+?>"; 
        System.Text.RegularExpressions.Match m = 
            System.Text.RegularExpressions.Regex.Match(input, pattern, 
            System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline); 
        if (m.Success) 
        { 
            string src = getSrc(m.Value); 
            return src;
        } 
        else 
        { 
            return ""; 
        } 
    }
    
    string getSrc(string input) 
    { 
        string pattern = "src=[\'|\"](.+?)[\'|\"]"; 
        System.Text.RegularExpressions.Regex reImg = new System.Text.RegularExpressions.Regex(pattern,
            System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline); 
        System.Text.RegularExpressions.Match mImg = reImg.Match(input); 
        if (mImg.Success) 
        {
            return mImg.Value.Replace("src=", "").Replace("\"", ""); ; 
        }

        return string.Empty; 
     } 
}
This replace wrong sitename with the correct name used by blog (getting it from BlogSettings.Instance.Name); and it make possible to set your twitter account by configuring it under blogengine admin backend.

Please apologize me for that inconvenience, have a good day.
Aug 9, 2014 at 7:23 PM
Hey man... no problem... thanks for the help.

Greg