user964986
user964986

Reputation: 125

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);

Upvotes: 10

Views: 11367

Answers (2)

Doug S
Doug S

Reputation: 10315

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);

Upvotes: 25

Anatoly Lubarsky
Anatoly Lubarsky

Reputation: 3036

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

Upvotes: 2

Related Questions