我想在後面的代碼中爲我的網站創建具有博客部分的元標記。所以每個博客都會有自己的標題和形象。因此在代碼背後創建。只是想確定這是否正確,Facebook/Google +會識別它。在asp.net中動態創建Facebook共享元標記[og:]
後面的代碼
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;
}
}
}
生成於Facebook和谷歌的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">
+它說,你必須有這種格式的meta標籤。
<meta content="No appointment necessary. We hear you coming." property="og:title">
而不是屬性關鍵字我有名字。我不知道如何在asp.net中創建。它對Facebook有效嗎?
請幫忙