Showing posts with label dynamic meta tags. Show all posts
Showing posts with label dynamic meta tags. Show all posts

Oct 9, 2013

How to add meta tags in Asp.net from the master page

Add meta tags in content pages under master page:


Master page:

<head runat="server">
<asp:Literal ID="ltrCtrl" runat="server"></asp:Literal>
</head>


Normal/ChildPage:

 
Sample.aspx.cs Page on pageload

Literal ltr = (Literal)this.Master.FindControl("ltrCtrl");
        StringBuilder metatag = new StringBuilder();
        metatag.Append("<meta name=\"description\" content=\"description here. \" />");
        metatag.Append("<meta name=\"keywords\" content=\"keyword, keywords here\"/>");
        ltr.Text = metatag.ToString();

i am using this .. its working fine for me.

Mar 2, 2010

How to add title of page dynamically in asp.net

this.Page.Title = "Movie Tickets, Theater Showtimes, telugu
movies,hindi movies,english movies,online movie tickets, eticket - ticketdada";

Dynamic Meta Tags from SQL Database

es you can add meta tags from SQL database. here is a small sample to give you the idea,
you can improvize according to your needs. Hope i understood your correctly.

%@ Page Title="" Language="C#"
 MasterPageFile="MetaTagMasterPage.master" 
AutoEventWireup="true" 
CodeFile="MetaTagforContentPages.aspx.cs" 
Inherits="General_MetaTagforContentPages" %>

<asp:Content ID="Content1" 
ContentPlaceHolderID="cpHeadMain" Runat="Server">
<title id="title" runat="server">
Initial Title Here</title>
<meta name="description" content="description" 
 id="description" runat="server" />
<meta name="keywords" content="keys" 
id="keywords" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" 
 Runat="Server">
    
</asp:Content>
 
 

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class General_MetaTagforContentPages : 
System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string query = "select * from MetaInfo";
 SqlConnection myconnection = new SqlConnection
(ConfigurationManager.ConnectionStrings
["MenuDbConnectionString"].ConnectionString);
        SqlCommand SqlCmd = null;
        SqlCmd = new SqlCommand(query, myconnection);
        SqlCmd.Connection.Open();
        SqlCmd.ExecuteNonQuery();

        SqlDataAdapter ad = new SqlDataAdapter(SqlCmd);
        DataTable dt = new DataTable();
        ad.Fill(dt);


 title.InnerHtml = dt.Rows[0]["PageTitle"].ToString();
 description.Attributes.Add("content" ,dt.Rows[0]
["MetaDesc"].ToString());
 keywords.Attributes.Add("content" ,dt.Rows[0]
["MetaKeyword"].ToString());
        

    }
}
hope this helps or gives you an idea
Thanks


 

Create Meta Tags Programmatically in ASP.NET 2.0

If you have been programming Web, you may be familiar with the meta tags in an HTML page. The meta tags are used to provides keywords etc in an HTML page.
Now in ASP.NET 2.0, you can add these meta tags programmatically. The HtmlMeta class provides programmatic access to the HTML <meta> element on the server. The HTML <meta> element is a container for data about the rendered page, but not page content itself.
The Name property of HtmlMeta provides the property name and the Content property is used to specify the property value. The Scheme property to specify additional information to user agents on how to interpret the metadata property and the HttpEquiv property in place of the Name property when the resulting metadata property will be retrieved using HTTP.
The following code shows how to add meta tags to a page programmatically.
private void CreateMetaTags()
{
   HtmlMeta hm = new HtmlMeta();

    HtmlHead head = (HtmlHead)Page.Header;

    hm.Name = "Keywords";
    hm.Content = "C#, Csharp, C-sharp, .NET";
    head.Controls.Add(hm);
}
Similarly, you can add multiple meta tags to the header.