What is MTG?
.NET language that you use in your project is not important.
Usage
First, you have to Add Reference "DA.MetaTagGenerator.dll" to your ASP.Net Web Forms or MVC project.
ASP.Net Web Forms
Reference to "DA.MetaTagGenerator" namespace in your page.
using DA.MetaTagGenerator;
You can generate tags in two ways.
1. Generate tags into <head>..</head> tag. :
protected void Page_Load(object sender, EventArgs e) { MetaTagGenerator gen = MetaTagGenerator.CreateInstance(this); // ... gen.GenerateTags(); }
2. Generate tags to a string variable
<head id="Head1" runat="server"> <title></title> <asp:Literal ID="litTag" runat="server" /> </head>
protected void Page_Load(object sender, EventArgs e) { MetaTagGenerator gen = MetaTagGenerator.CreateInstance(this); // ... litTag.Text = gen.ToString(); // or // string tags = gen.ToString(); }
ASP.Net MVC
<head> @using DA.MetaTagGenerator @{ MetaTagGenerator gen = MetaTagGenerator.CreateForMVC(); gen.MetaTags = new Tags.MetaTagsInfo { Charset=Constants.UTF8, Title = "Deneme dünyası ğüşiöç", Description = "merhaba dünya", Copyright = "Devrim Altınkurt" }; } @gen.ToStringForMVC() </head>
JSON-LD Scripts
v1 only supports "Article" object.
MetaTagGenerator gen = MetaTagGenerator.CreateInstance(this); gen.RichSnippetsTags.Article = new Tags.RichSnippetArticleInfo { Author = "Devrim Altınkurt", DateModified = DateTime.Today.ToISO8601DateString(), DatePublished = DateTime.Today.ToISO8601DateString(), Decription = "Meta Generator for ASP.NET Description", Image = new Tags.RichSnippetImageInfo { Height = 148, Url = "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", Width = 150 }, Publisher = "Devrim Altınkurt", PublisherLogo = new Tags.RichSnippetImageInfo { Height = 148, Url = "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", Width = 150 }, Title = "Meta Generator for ASP.NET", Url = "http://metataggenerator.daltinkurt.com" }; gen.GenerateTags();
<script type="application/ld+json"> [ { "@context": "http://schema.org", "@type": "NewsArticle", "mainEntityOfPage":{ "@type":"WebPage", "@id":"http://metataggenerator.daltinkurt.com" }, "headline": "Meta Generator for ASP.NET", "image": { "@type": "ImageObject", "url": "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", "height": 148, "width": 150 }, "datePublished": "2016-03-29T00:00:00.0000000+03:00", "dateModified": "2016-03-29T00:00:00.0000000+03:00", "author": { "@type": "Person", "name": "Devrim Altınkurt" }, "publisher": { "@type": "Organization", "name": "Devrim Altınkurt", "logo": { "@type": "ImageObject", "url": "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", "width": 150, "height": 148 } }, "description": "Meta Generator for ASP.NET Description" } ] </script>
Robots Tag
You can use robots tags via enum values:
gen.MetaTags.Robots = RobotTypes.FOLLOW | RobotTypes.INDEX | RobotTypes.NOTRANSLATE;
<meta name="robots" content="index, follow, notranslate">
Working with dates
When you want to define a date meta tag, you have to write DateTime value formatted as ISO8601.
So you must convert DateTime values to ISO8601 format like 'yyyy-MM-dd'.
There is a built-in extension method in MTG for this:
MetaTagGenerator gen = MetaTagGenerator.CreateInstance(this); gen.MetaTags.Date = new DateTime(2014, 7, 4).ToISO8601DateString(); gen.MetaTags.SearchDate = new DateTime(2014, 7, 4).ToISO8601DateString(); gen.OGMetaTags.BookInfo.ReleaseDate = new DateTime(2014, 7, 4).ToISO8601DateString(); gen.RichSnippetsTags = new Tags.RichSnippetsInfo { Article = new Tags.RichSnippetArticleInfo { Url = "http://metataggenerator.daltinkurt.com", DateModified = new DateTime(2014, 7, 4).ToISO8601DateString(), DatePublished = new DateTime(2014, 7, 4).ToISO8601DateString() } }; gen.GenerateTags();
<meta name="Date" content="2014-07-04T00:00:00.0000000"> <meta name="search_date" content="2014-07-04T00:00:00.0000000"> <script type="application/ld+json"> [ { "@context": "http://schema.org", "@type": "NewsArticle", "mainEntityOfPage":{ "@type":"WebPage", "@id":"http://metataggenerator.daltinkurt.com" }, .... "datePublished": "2014-07-04T00:00:00.0000000", "dateModified": "2014-07-04T00:00:00.0000000", .... } ] </script>
Full sample
DateTime date = new DateTime(2010, 4, 7); MetaTagGenerator gen = MetaTagGenerator.CreateInstance(this); gen.FBMetaTags = new Tags.FBTagsInfo { AdminId = 12345, AdminIds = new long[] { 12345, 67890 }, AppId = 12345, Pages = new long[] { 12345, 67890 }, ProfileId = 12345 }; gen.MetaTags = new Tags.MetaTagsInfo { Abstract = "xxx", Author = "xxx", Category = "xxx", Charset = Constants.UTF8, Classification = "xxx", ContentType = Constants.UTF8_httpeqiv, Copyright = "xxx", CopyrightUrl = "http://example.com/copyright.html", Coverage = "xxx", Date = date.ToISO8601DateString(), Description = "xxx", Designer = "xxx", Directory = "xxx", Distribution = "xxx", Generator = "xxx", HandheldFriendly = HandheldFriendlyTypes.True, IdentifierUrl = "xxx.html", //KeywordArray=new string["keyword1","keyword2"], Keywords = "keywords1, keywords2", Language = "en", Medium = "xxx", MobileOptimized = "320", OriginalSource = "xxx", Owner = "xxx", PageKey = "xxx", PageName = "xxx", Rating = "xxx", //Refresh="", ReplyTo = "xxx@example.com", RevisitAfter = "7 days", SearchDate = date.ToISO8601DateString(), Robots = RobotsTypes.INDEX | RobotsTypes.NOFOLLOW, Subject = "xxx", Subtitle = "xxx", Summary = "xxx", SyndicationSource = "http://example.com/copyright.html", //Target="", Title = "Page title", Topic = "xxx", Url = "http://example.com/example.aspx" }; gen.MetaTags.LinkTags.Add(new Tags.LinkTagInfo { Rel = LinkTagDefs.Alternate, Type = FileTypeDefs.Atom, Href = "example.html", Title = "title" }); gen.MetaTags.LinkTags.Add(new Tags.LinkTagInfo { Rel = LinkTagDefs.Favicon, Type = FileTypeDefs.Image_ico, Href = "/favicon.ico" }); // ... gen.OGMetaTags = new Tags.OGTagsInfo { AlternateLocales = new string[] { "fr", "jp" }, ArticleInfo = new Tags.OGArticleInfo { Authors = new Tags.OGProfileInfo[] { new Tags.OGProfileInfo { FirstName = "Devrim", LastName = "Altınkurt", Gender = GenderTypes.Male, Username = "daltinkurt" } }, ExpirationTime = date.ToISO8601DateString(), ModifiedTime = date.ToISO8601DateString(), PublishedTime = date.ToISO8601DateString(), Section = "xxx", Tags = new string[] { "tag1", "tag2" } }, Description = "xxx", Url = "xxx.html", Type = OGTypes.Article, Title = "title", Site_Name = "daltinkurt", Locale = "en", //AudioInfo= //ImageInfo= //VideoInfo= }; gen.TwitterTags = new Tags.TwitterCardInfo { Card = TwitterCardTypes.App, Site = "twitter", Description = "Cannonball is the fun way to create and share stories and poems on your phone.", App = new Tags.TwitterAppInfo { Country = "US", GooglePlayId = "io.fabric.samples.cannonball", GooglePlayName = "Cannonball", GooglePlayUrl = "http://cannonball.fabric.io/poem/5149e249222f9e600a7540ef", IpadId = "929750075", IpadName = "Cannonball", IpadUrl = "cannonball://poem/5149e249222f9e600a7540ef", IphoneId = "929750075", IphoneName = "Cannonball", IphoneUrl = "cannonball://poem/5149e249222f9e600a7540ef" } }; gen.RichSnippetsTags.Article = new Tags.RichSnippetArticleInfo { Author = "Devrim Altınkurt", DateModified = date.ToISO8601DateString(), DatePublished = date.ToISO8601DateString(), Decription = "Meta Generator for ASP.NET Description", Image = new Tags.RichSnippetImageInfo { Height = 148, Url = "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", Width = 150 }, Publisher = "Devrim Altınkurt", PublisherLogo = new Tags.RichSnippetImageInfo { Height = 148, Url = "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", Width = 150 }, Title = "Meta Generator for ASP.NET", Url = "http://metataggenerator.daltinkurt.com" }; gen.GenerateTags();
<meta charset="utf-8"> <meta name="title" content="Page title"> <meta name="description" content="xxx"> <meta name="author" content="xxx"> <meta name="copyright" content="xxx"> <meta name="language" content="en"> <meta name="keywords" content="keywords1, keywords2"> <meta name="robots" content="nofollow, index"> <meta name="subject" content="xxx"> <meta name="abstract" content="xxx"> <meta name="topic" content="xxx"> <meta name="summary" content="xxx"> <meta name="classification" content="xxx"> <meta name="designer" content="xxx"> <meta name="reply-to" content="xxx@example.com"> <meta name="owner" content="xxx"> <meta name="url" content="http://example.com/example.aspx"> <meta name="identifier-URL" content="xxx.html"> <meta name="directory" content="xxx"> <meta name="coverage" content="xxx"> <meta name="distribution" content="xxx"> <meta name="rating" content="xxx"> <meta name="revisit-after" content="7 days"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="pagename" content="xxx"> <meta name="subtitle" content="xxx"> <meta name="generator" content="xxx"> <meta name="HandheldFriendly" content="true"> <meta name="MobileOptimized" content="320"> <meta name="Date" content="2010-04-07T00:00:00.0000000"> <meta name="search_date" content="2010-04-07T00:00:00.0000000"> <meta name="medium" content="xxx"> <meta name="syndication-source" content="http://example.com/copyright.html"> <meta name="original-source" content="xxx"> <meta name="pageKey" content="xxx"> <link rel="alternate" title="title" type="application/atom+xml" href="example.html"> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"> <meta property="fb:admins" content="12345"> <meta property="fb:admins" content="67890"> <meta property="fb:app_id" content="12345"> <meta property="fb:profile_id" content="12345"> <meta property="fb:pages" content="12345"> <meta property="fb:pages" content="67890"> <meta property="og:title" content="title"> <meta property="og:description" content="xxx"> <meta property="og:type" content="article"> <meta property="og:url" content="xxx.html"> <meta property="og:locale" content="en"> <meta property="og:locale:alternate" content="fr"> <meta property="og:locale:alternate" content="jp"> <meta property="og:site_name" content="daltinkurt"> <meta property="article:expiration_time" content="2010-04-07T00:00:00.0000000"> <meta property="article:modified_time" content="2010-04-07T00:00:00.0000000"> <meta property="article:published_time" content="2010-04-07T00:00:00.0000000"> <meta property="article:section" content="xxx"> <meta property="article:tag" content="tag1"> <meta property="article:tag" content="tag2"> <meta property="profile:first_name" content="Devrim"> <meta property="profile:last_name" content="Altınkurt"> <meta property="profile:username" content="daltinkurt"> <meta property="profile:gender" content="male"> <meta property="twitter:card" content="app"> <meta property="twitter:site" content="twitter"> <meta property="twitter:app:name:iphone" content="Cannonball"> <meta property="twitter:app:id:iphone" content="929750075"> <meta property="twitter:app:url:iphone" content="cannonball://poem/5149e249222f9e600a7540ef"> <meta property="twitter:app:name:ipad" content="Cannonball"> <meta property="twitter:app:id:ipad" content="929750075"> <meta property="twitter:app:url:ipad" content="cannonball://poem/5149e249222f9e600a7540ef"> <meta property="twitter:app:name:googleplay" content="Cannonball"> <meta property="twitter:app:id:googleplay" content="io.fabric.samples.cannonball"> <meta property="twitter:app:url:googleplay" content="http://cannonball.fabric.io/poem/5149e249222f9e600a7540ef"> <script type="application/ld+json"> [ { "@context": "http://schema.org", "@type": "NewsArticle", "mainEntityOfPage":{ "@type":"WebPage", "@id":"http://metataggenerator.daltinkurt.com" }, "headline": "Meta Generator for ASP.NET", "image": { "@type": "ImageObject", "url": "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", "height": 148, "width": 150 }, "datePublished": "2010-04-07T00:00:00.0000000", "dateModified": "2010-04-07T00:00:00.0000000", "author": { "@type": "Person", "name": "Devrim Altınkurt" }, "publisher": { "@type": "Organization", "name": "Devrim Altınkurt", "logo": { "@type": "ImageObject", "url": "http://metataggenerator.daltinkurt.com/assets/img/logo-main.png", "width": 150, "height": 148 } }, "description": "Meta Generator for ASP.NET Description" } ] </script> <title> Page title </title>
Files Structure
/DA.MetaTagGenerator
Class Library/Generators
All internal generator classesFBTagGenerator.cs
Facebook tag generatorHtmlMetaTagGenerator.cs
Html meta tag generatorOGMetaGenerator.cs
Open Graph tag generatorRichSnippetsGenerator.cs
JSON-LD script tag generatorTwitterCardGenerator.cs
Twitter card tag generator
/OtherClasses
Various usefull classesConstants.cs
UTF8, UTF8_httpeqivDefinitions.cs
FileTypeDefs, LinkTagDefs, Locales, OpenGraphDefsEnums.cs
RobotsTypes, OGTypes, DeterminerTypes, CrossOriginTypes, GenderTypes, TwitterCardTypes, HandheldFriendlyTypesExtensionMethods.cs
IsNullOrEmpty, ToISO8601DateString, ToEncodedString
MetaTagGenerator.cs
Main process classMetaTagInfo.cs
All tag info classes
Validators
References
HTML5 tags:
- http://www.w3schools.com/tags/tag_meta.asp
- https://support.google.com/webmasters/answer/79812?hl=en
- http://code.lancepollard.com/complete-list-of-html-meta-tags/#basic-html-meta-tags
Facebook & OpenGraph tags:
- https://developers.facebook.com/docs/sharing/opengraph
- https://developers.facebook.com/docs/sharing/webmasters#markup
- http://ogp.me/
Twitter card tags:
Schema.org JSON-LD Scripts: