Help with Headers Please Header.Controls.RemoveAt() Header.Controls.Add Dont Work...
-
Hello Everyone and thanks in advance for helping me with this. I need to programmatically locate and change the content of Description and Keyword metatags. Searching the internet, I have found a solution (not a solid one though) but it stopped working after I have changed the order of metatags (which I can understand). I have a masterpage site.master (with following code beside everything else as usual) where I set a default set of keywords and a default description (which are site-wide):
<head id="Head1" runat="server">
<title>My Default Page Title Here</title>
<meta http-equiv="Content-Language" content="tr"/>
<meta name="Description" content="My Default Description Here" />
<meta name="Keywords" content="these, are, my default, keywords" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254"/>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta name="Rating" content="General" />
<meta name="Author" content="Haluk " />
<meta name="Copyright" content="www.acme.com.tr" />
<meta name="revisit-after" content="1" />
<meta name="robots" content="all" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="favicon.ico" />
</head>and there are some asp pages (linked with site.master) where I want to be able to change Description and Keywords metatags for obvious SEO reasons. I placed following C# code in respective cs files:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class akademik_indirim : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Header.Controls.RemoveAt(2);
this.Page.Header.Controls.RemoveAt(2);
HtmlMeta child = new HtmlMeta();
child.Name = "Description";
child.Content = "Custom Description for This Page";
base.Master.Page.Header.Controls.Add(child);
HtmlMeta meta2 = new HtmlMeta();
meta2.Name = "Keywords";
meta2.Content = "custom keywords, for, seo, purposes";
base.Master.Page.Header.Controls.Add(meta2);