ASP.NET Change facebook og properties from content page

匆匆过客 提交于 2019-12-10 12:43:16

问题


I want to dynamically change in code behind facebook og properties like

< meta property="og:image" content="image_link" />
< meta property="og:title" content="title" />

How to do this?

btw. I'm adding regular meta tags like this:

HtmlMeta tag = new HtmlMeta();
tag.Name = "description";
tag.Content = message;
Page.Header.Controls.Add(tag);

回答1:


Here is how you add the proprietary Facebook "property" attribute to a standard META tag:

HtmlMeta tag = new HtmlMeta();
tag.Attributes.Add("property", "og:title");
tag.Content = "MyTitle"; // don't HtmlEncode() string. HtmlMeta already escapes characters.
Page.Header.Controls.Add(tag);



回答2:


if what you want is to add a property attribute in c# to HtmlControl this should be like so:

tag.Attributes.Add(KEY, VALUE);  

where KEY = "property" and VALUE = "og:image"

hope this helps



来源:https://stackoverflow.com/questions/7554749/asp-net-change-facebook-og-properties-from-content-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!