Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frds,
how to create dynamic meta tags with parameter in asp.net
for example:http://localhost/website/index.aspx
but rewriting page like this:http://localhost/website/home

In home page creating gridview ->user click on firstone url like this:localhost/website/home?id=1
how to write metatags with parameter
...
my code is



protected void Page_Load(object sender, EventArgs e)
{
string page = Request.Url.Segments[Request.Url.Segments.Length - 1];
DataTable dtMeta = this.GetData(page);

//Add Page Title
this.Page.Title = dtMeta.Rows[0]["Title"].ToString();

//Add Keywords Meta Tag
HtmlMeta keywords = new HtmlMeta();
keywords.HttpEquiv = "keywords";
keywords.Name = "keywords";
keywords.Content = dtMeta.Rows[0]["Keywords"].ToString();
this.Page.Header.Controls.Add(keywords);

//Add Description Meta Tag
HtmlMeta description = new HtmlMeta();
description.HttpEquiv = "description";
description.Name = "description";
description.Content = dtMeta.Rows[0]["Description"].ToString();
this.Page.Header.Controls.Add(description);
}

private DataTable GetData(string page)
{
string query = "SELECT Title, Description, Keywords FROM MetaTags WHERE LOWER(Page) = LOWER(@Page)";
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Page", page);
cmd.Connection = con;
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
Posted
Updated 7-Apr-15 23:45pm
v2
Comments
Sinisa Hajnal 8-Apr-15 6:42am    
Why, oh, why do you have page parameter as string?!

The question is not clear...what are you trying to do?
iamvinod34 8-Apr-15 13:15pm    
i want
how to write meta tags below link
http://localhost/website/Alldata?ID=23

Alldata--->all.aspx(rewriteing page)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900