Category Archives: Notepad

asp.net Masterpages and Metatags

There are a couple of ways to edit meta tags in MasterPages in asp.net (vb).

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Title = String.Format(“Master Page Tutorials :: About :: {0:d}”, DateTime.Now)

‘ Programmatically add a <meta> element to the Header
Dim keywords As New HtmlMeta()
keywords.Name = “keywords”
keywords.Content = “master page,asp.net,tutorial”

Page.Header.Controls.Add(keywords)

‘ Programmatically add a <meta> element to the Header
Dim description As New HtmlMeta()
description.Name = “description”
description.Content = “This is a Sample Description”

Page.Header.Controls.Add(description)

End Sub

New way: (thanks to: http://weblogs.asp.net/scottgu/archive/2010/01/05/asp-net-4-seo-improvements-vs-2010-and-net-4-0-series.aspx)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Title = String.Format(“Master Page Tutorials :: About :: {0:d}”, DateTime.Now)

Page.MetaDescription = “Hello World”
Page.MetaKeywords = “Some, keywords, that, go here”

End Sub

I prefer the output of the first type, even tho it has more code involved.