Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help with Headers Please Header.Controls.RemoveAt() Header.Controls.Add Dont Work...

Help with Headers Please Header.Controls.RemoveAt() Header.Controls.Add Dont Work...

Scheduled Pinned Locked Moved ASP.NET
csharphtmlcsswpfcom
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ortaparmak
    wrote on last edited by
    #1

    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);

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups