I am using a master page on a no of pages.How do I add meta description or meta keywords to each page

Dani AI

Generated

Short answer and a practical pattern you can use with master pages.

As asked, both the page-level directive approach and setting the Page.MetaDescription (as mentioned by and ) work for simple cases, but they get hard to maintain for many pages. A more robust pattern is to expose the master page head for page-specific content (make the master page’s <head> a server-side element and include a head ContentPlaceHolder), then either put per-page meta tags into that placeholder or add them programmatically from the content page. See Microsoft’s guidance on master-page head/content placeholders. (learn.microsoft.com)

Two practical options you can apply immediately:

  • Declarative: put a ContentPlaceHolder inside the master <head runat="server"> and add a small <asp:Content> for that placeholder on each content page to provide page-specific <meta> tags (best for mostly static pages).

  • Programmatic: for dynamic pages, create HtmlMeta objects and add them to Page.Header.Controls from code-behind so values can be pulled from a database or built from the page content. Example (C#):

    var meta = new System.Web.UI.HtmlControls.HtmlMeta();
    meta.Name = "description";
    meta.Content = pageDescription; // build or fetch this
    Page.Header.Controls.Add(meta);

    Microsoft documents this programmatic approach for adding meta tags to the head. (learn.microsoft.com)

SEO/caveats: meta descriptions should be unique and descriptive for each page — Google may use them for the snippet but there’s no fixed character limit (snippets are truncated to fit device width), so front-load the important text and generate descriptions programmatically where manual editing isn’t feasible. Also skip relying on meta keywords — Google ignores them. (developers.google.com)

Quick troubleshooting: confirm the master page’s <head> has runat="server"; check the page source (view-source) to see whether your meta tag was emitted; avoid adding the same meta in multiple places (that can create duplicates); if using output caching, ensure you don’t cache a generic head for pages that need unique metadata. If you need a compact reference, Microsoft’s master-page + head examples are a good starting point. (stackoverflow.com)

References: Master pages and head/content placeholders, Programmatically adding meta tags to the head, Google: meta description/snippet guidance, Google doesn’t use meta keywords (Matt Cutts).

Recommended Answers

All 2 Replies

I am using a master page on a no of pages.How do I add meta description or meta keywords to each page

<%@ Page Language="C#" MasterPageFile="~/IdeaScope.master" 
  AutoEventWireup="true" CodeFile="is.aspx.cs" Inherits="_is"
  CodeFileBaseClass="BasePage" 
  
  Title="Effective Customer Feedback Management, 
      Improve Customer Commmunication" 
  
  Meta_Keywords="Customer Feedback, Customer Opinion, feedback, opinion,
       idea, ideas, idea management, customer feedback management,         
        product management, product manager, product marketing,         
        product marketing manager"
                              
  Meta_Description="IdeaScope is an on-demand and embedded solution that 
       allows you to capture, prioritize and centrally manage customer 
       feedback. Make your customer feedback process more efficient. Save 
       time and involve more stakeholders without significant cost." 
  %>

You can also add these tags in code behind like below if you are using .net 3.5 or later

Page.MetaDescription="description";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.