我的页面中有一个赞按钮。单击按钮时,我正在尝试在 facebook 中发送以下标签信息...
<meta property="og:title" content="Title" />
<meta property="og:description" content="Description" />
<meta property="og:url" content="url info" />
<meta property="og:image" content="image url" />
以下是我的喜欢按钮框架
<iframe frameborder="0" scrolling="no" allowtransparency="true"
style="border: none; overflow: hidden; width: 260px; height: 35px;"
src="http://www.facebook.com/plugins/like.php?
href=http://localhost:49334/WebForm1.aspx&send=false&
layout=button_count&width=100&show_faces=false&
action=like&colorscheme=light&font=arial&height=35">
</iframe>
以下是动态处理元标记的第一种方法。
var fbTitleTag = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:title",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterTitle").Value
};
var fbDesc = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:description",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterDescription").Value
};
var fbUrl = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:url",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterURL").Value
};
var fbImage = new MetaTag
{
AgentPageURL = "/",
MetaTagName = "og:image",
UserSiteName = CurrentAgent.UserSiteName,
MetaTagContent = Request.Cookies.Get("MasterImage").Value
};
var tags = new MetaTagCollection { fbTitleTag, fbDesc, fbUrl, fbImage };
Literal ltMetaTags = null;
ltMetaTags = (Literal)this.Master.FindControl("ltMetaTags");
MetaTags(tags, "wsws", "/", ltMetaTags, true);
public static void MetaTags(MetaTagCollection MetaTags, string name, string strRawURL, Literal ltlMetaHolders, bool isProp)
{
// ltlMetaHolders.Text = "";
foreach (AgentMetaTag oAgentMetaTag in agentMetaTags)
{
if (string.Compare(strRawURL, oAgentMetaTag.AgentPageURL, true) == 0)
{
if (oAgentMetaTag.MetaTagName.ToLower().Trim() != "footer" && oAgentMetaTag.MetaTagName.ToLower().Trim() != "title")
{
if (oAgentMetaTag.MetaTagName.ToLower().Trim() == "fbtitle")
oAgentMetaTag.MetaTagName = "title";
RenderMetaTagByContentName(ltlMetaHolders, oAgentMetaTag.MetaTagName, oAgentMetaTag.MetaTagContent, isProp);
}
}
}
}
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);
}
以下是动态处理元标记的第二种方法。
HtmlMeta tag = new HtmlMeta();
tag.Attributes.Add("property", "og:title");
tag.Content = "Title";
Page.Header.Controls.Add(tag);
HtmlMeta tag1 = new HtmlMeta();
tag1.Attributes.Add("property", "og:description");
tag1.Content = "Desc";
Page.Header.Controls.Add(tag1);
HtmlMeta tagurl = new HtmlMeta();
tagurl.Attributes.Add("property", "og:url");
tagurl.Content = "URL info";
Page.Header.Controls.Add(tagurl);
HtmlMeta tagimg = new HtmlMeta();
tagimg.Attributes.Add("property", "og:img");
tagimg.Content = "Image URL";
Page.Header.Controls.Add(tagimg);
最后它呈现元标记如下..
<meta property="og:title" content="Title" />
<meta property="og:description" content="Description" />
<meta property="og:url" content="url info" />
<meta property="og:image" content="image url" />
现在,当我单击Like button
它时,它只发送 url。并且不发送Description/Image/Title
.
我正在使用链接“http://developers.facebook.com/tools/debug”。它说Description/Image/Title
缺少。
有任何想法吗?