OpenGraph tags generator for .NET. Built according to OpenGraph spec found here
You can find NuGet package here or install it via package manager console:
Install-Package Simplr.OpenGraph
Helper class that generates tags for OpenGraph has two main methods:
OGHelper.GetMetadata<T>(IOGType<T> metadata)
OGHelper.GetMetadata<T>(OGMetadata metadata, IOGType<T> contentMetadata)
Both return string with generated meta tags.
-
Create page defining metadata object:
var metadata = new OGMetadata() { Title = "My cool page title", Url = new Uri("https://mypage.buzz"), Description = "My page that has a cool title and even cooler site name!", SiteName = "Cool page" };
Objects can be filled fully or partially.
-
Call helper method to generate meta tags
string tags = OGHelper.GetMetadata(metadata);
-
Add meta tags to your HTML -> HEAD website
-
You can test if it works in Facebook's debug tool here
Some of our pages have more specific data, e.g. they represent Music Song, Music Album, Profile, Book, etc.
If you want to add that specific metadata in addition to basic one, create a global type object from provided models or create your own (section bellow)
var metadata = new OGMetadata() {
Title = "My cool page title",
Url = new Uri("https://mypage.buzz"),
Description = "My page that has a cool title and even cooler site name!",
SiteName = "Cool page"
};
var customMetadata = new OGProfile(){
FirstName = "John",
LastName = "Smith",
Username = "johnysmith"
}
string tags = OGHelper.GetMetadata(metadata, customMetadata);
If your page data does not fall into any of global types, you can create custom ones.
To do that, simply create your type and inherit a global type or implement IOGType interface and define your own properties.
class MyPageObj : IOGType {
public string Type {
get { return "MyType"; }
}
public string MyProperty {
get { return "MyPropertyValue"; }
}
}
And use it like in "Specific page type example".