Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Change facebook og properties from content page

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);
like image 399
user964986 Avatar asked Sep 26 '11 12:09

user964986


2 Answers

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);
like image 182
Doug S Avatar answered Nov 08 '22 17:11

Doug S


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

like image 45
Anatoly Lubarsky Avatar answered Nov 08 '22 16:11

Anatoly Lubarsky