Subscribe to the ASP.NET Robot RSS Feed

ASP.NET Title Tag and Meta Tags




Meta tags and title tag used to provide some basic information about a web page like page title, page description, page keywords and more.
I recommend don’t use more than 65 Characters (Including Spaces) for a Page Title Tag, for the meta description tag don’t use more than 150 Characters (Including Spaces) and for meta keywords tag Pick the 10 or 15 terms that most accurately describe the content of the page. But remember that today most of the search engines ignoring the Meta keywords tag.


This tags you can set in the head section of the page like this:

<head runat="server">
    <title>Your Page Title</title>
    <meta name="description" content="Your Page Description" />
    <meta name="keywords" content="Your Page Keywords" />
</head>



   
     

Define Title Tag and Meta Tags in ASP.NET 4.0

  

The following code demonstrates how you can set this properties programmatically from code behind in ASP.NET framework 4.0 within Page_Load() event handler

protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Your Page Title";
        Page.MetaDescription = "Your Page Description";
        Page.MetaKeywords = "Your Page Keywords";
    }

Or you can declare these tags in the @Page directive at the top of .aspx pages like this:

<%@ Page Title="Your Page Title" 
         MetaDescription="Your Page Description" 
         MetaKeywords="Your Page Keywords" 
         Language="C#" 
         AutoEventWireup="true" 
         CodeFile="Default.aspx.cs" 
         Inherits="_Default"  %>



    
    

Declare Title Tag and Meta Tags in ASP.NET 3.5 and Blow

 

The following code demonstrates how you can declare this properties programmatically from code behind in ASP.NET framework 3.5 and blow within Page_Load() event handler

protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Your Page Title";

        HtmlMeta metaDescription = new HtmlMeta();
        metaDescription.Name = "description";
        metaDescription.Content = "Your Page Description";
        Page.Header.Controls.Add(metaDescription);

        HtmlMeta metaKeywords = new HtmlMeta();
        metaKeywords.Name = "keywords";
        metaKeywords.Content = "Your Page Keywords";
        Page.Header.Controls.Add(metaKeywords);
    }

Add New Comment:

Facebook del.icio.us FriendFeed Digg it Google Buzz Linked in MySpace Reddit Stumbleupon Twitter Technorati