TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chinna Netha
NA
282
138.2k
how to create dynamic meta tags with parameter in asp.net?
Apr 8 2015 6:21 AM
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;
}
}
}
}
Reply
Answers (
2
)
how to update and send data to arduino
ASP .NET Text box