Add Meta Tags In Asp.Net Pages And MasterPage

Adding Meta Tags In aspx Page and Content Pages of MasterPage In Asp.Net Using C# And VB Dynamically.

We can write code mentioned below in Page_Load Event to add dynamic tags.


C# CODE
protected void Page_Load(object sender, EventArgs e)
    {   //Add Description 
        HtmlMeta desc = new HtmlMeta();
        desc.Name = "Description";
        desc.Content = "Your page description";
        Header.Controls.Add(desc);

        // Add Keywords
        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "Keywords";
        keywords.Content = "Your comma separated keywords";
        Header.Controls.Add(keywords);
    }

VB.NET CODE
Protected Sub Page_Load(sender As Object, e As EventArgs)
 'Add Description 
 Dim desc As New HtmlMeta()
 desc.Name = "Description"
 desc.Content = "Your page description"
 Header.Controls.Add(desc)

 ' Add Keywords
 Dim keywords As New HtmlMeta()
 keywords.Name = "Keywords"
 keywords.Content = "Your comma separated keywords"
 Header.Controls.Add(keywords)
End Sub

To add Meta Tags in site using Master Page we need to add tags in HTML source of content pages as mentioned below.

Head ContentPlaceHolder of content page.

HTML SOURCE OF CONTENT PAGE
   1:  <asp:Content ID="Content1" ContentPlaceHolderID="head" 
   2:               Runat="Server">
   3:  <meta name="Description" content="Your page description"/>
   4:  </asp:Content>


If you like this post than join us or share

0 comments:

Find More Articles