我正在尝试在后面的代码中为我的网站创建元标记,该网站有一个博客部分。所以每个博客都会有自己的标题、图片。因此在后面的代码中创建。只是想确定这是否正确,Facebook/Google+ 会识别它。
代码背后
private void AddMetaTagsForPage(object tempObject)
{
string[] metaTags = {"og:title", "og:site_name", "og:type", "og:url", "og:image"};
foreach(string str in metaTags)
{
HtmlMeta tag = new HtmlMeta();
switch(str)
{
case "og:title":
tag.Name = str;
tag.Content = tempObject.ChallengeTitle;
Page.Header.Controls.Add(tag);
break;
case "og:site_name":
tag.Name = str;
tag.Content = "http://www.mysite.com";
Page.Header.Controls.Add(tag);
break;
case "og:type":
tag.Name = str;
tag.Content = "blog";
Page.Header.Controls.Add(tag);
break;
case "og:url":
tag.Name = str;
tag.Content = HttpContext.Current.Request.Url.AbsoluteUri;
Page.Header.Controls.Add(tag);
break;
case "og:image":
tag.Name = str;
tag.Content = String.Format("http://static.mountainwarehouse.com" + tempObject.ChallengeImageURL);
Page.Header.Controls.Add(tag);
break;
}
}
}
生成的 HTML
<meta content="No appointment necessary. We hear you coming." name="og:title">
<meta content="http://www.mysite.com" name="og:site_name">
<meta content="blog" name="og:type">
<meta content="http://dev.mysite.com/entries/viewentry.aspx?entryId=34"
name="og:url">
<meta content="http://static.mysite.com/Images/2a7803a2-e8f1-424c-9f53-3ddc1fe33c3e.jpg" name="og:image">
在 facebook 和 google+ 上,它说你必须有这种格式的元标记。
<meta content="No appointment necessary. We hear you coming." property="og:title">
我有名字而不是属性关键字。我不知道如何在 asp.net 中创建它。它对脸书有效吗?
请帮忙