我已经使用以下代码在我的网站上使用FB Like ...但是点击就像将帖子发布到FB “Jonny喜欢http://www.site.com”但不是实际的网址喜欢的网页,即“www.site.com/reports/1”。
我已将此代码放在主文件中......
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
并在各自的页面....
<div class="fb-like" data-href="http://citizen.tricedeals.com" data-send="true" data-width="450" data-show-faces="false" data-font="verdana"></div>
答案 0 :(得分:1)
您必须在执行时实施以下元标记信息 像新闻......
代码背后
public class MetaTag
{
public string PageURL { get; set; }
public string TagName { get; set; }
public string MetaTagContent { get; set; }
public string SiteName { get; set; }
}
var fbTitleTag = new MetaTag
{
PageURL = "/",
MetaTagName = "og:title",
SiteName = "Your Site Name",
MetaTagContent = "Your Title"
};
var fbDesc = new MetaTag
{
PageURL = "/",
MetaTagName = "og:description",
SiteName = "Site Name",
MetaTagContent = "Your Description"
};
var fbUrl = new MetaTag
{
PageURL = "/",
MetaTagName = "og:url",
SiteName = "Site Name",
MetaTagContent = "URL"
};
var fbImage = new MetaTag
{
PageURL = "/",
MetaTagName = "og:image",
SiteName = "Site Name",
MetaTagContent = "Image URL"
};
System.Collections.Generic.List<MetaTag> List = new System.Collections.Generic.List<MetaTag>();
List.Add(fbTitleTag);
List.Add(fbDesc);
List.Add(fbUrl);
List.Add(fbImage);
RenderMetaTags(List, "SiteName", strRawUrl, ltMetaTags);
Here ltMetaTags is the Literal control to place in Master page. See bottom of the asnwer.
public static void RenderMetaTags(List<MetaTag> MetaTags, string sitename, string strRawURL, Literal ltlMetaHolders)
{
// ltlMetaHolders.Text = "";
foreach (MetaTag oAgentMetaTag in MetaTags)
{
RenderMetaTagByContentName(ltlMetaHolders, oAgentMetaTag.MetaTagName, oAgentMetaTag.MetaTagContent);
}
}
public static void RenderMetaTagByContentName(Literal ltlMetaHolder, string contentName, string content, bool isProp)
{
var metaTagFromat = isProp ? "<meta property=\"{0}\" content=\"{1}\" />" : "<meta name=\"{0}\" content=\"{1}\" /> ";
ltlMetaHolder.Text += string.Format(metaTagFromat, contentName, content);
}
主页中的以下是母版页的标题文字
<asp:Literal ID="ltMetaTags" Mode="Transform" runat="server"></asp:Literal>