Search
Windows Server

Microsoft Content Management Server : Preparing Postings for Search Indexing - Outputting META Tags

Published 4 min readBy Programming4us Editorial Team
As well as the ROBOTS META tag, you can emit other META tags to help indexing by the particular search engine you are working with. Common tags used by search engines include the tag and the Description and Keywords META tags. <p>In MCMS, channels and postings have Description and DisplayName properties, which are often suitable for the Description META tag and the <title> tag respectively.</p> <p>Custom properties can also be used as META tags and rendered as <meta name="CustomPropertyName" content="CustomPropertyValue"></p> <br/> <p>Keywords can be entered by authors and stored as custom property values. What you will need to do then is to retrieve these values from the repository and display them as META tags in the head region of the page.</p> <p>There are several ways you can go about this:</p> <ul><li><p>The fastest method is to simply use <%= %> constructs or Response.Write() calls within the template HTML code.</p></li><li><p>If content that resides in custom properties or placeholders, you can retrieve it using code-behind files.</p></li></ul> <p>Like regular controls, use a web user control to share code among template files in the same project. If you need to generate the same set of tags across pages stored in multiple projects, consider writing a custom control as we did for the ROBOTS tag earlier.</p> <h2 id="using-within-template-files">Using <%= %> within Template Files</h2> <p>Use <%= %> constructs or the Response.Write() method when you need to display single pieces of information, like display names and descriptions. Let’s take a closer look by implementing the constructs in the Columns.aspx template file of the Tropical Green project.</p> <table><tbody><tr><td><p><strong>1. </strong></p></td><td><p>Open the Tropical Green project. Open the Columns.aspx template file in HTML view.<br/><br/></p></td></tr><tr><td><p><strong>2. </strong></p></td><td><p>At the top of the page, add a page directive to import the Microsoft.ContentManagement.Publishing namespace. This allows us to access its classes (such as CmsHttpContext) from within the template file. <%@ Import Namespace="Microsoft.ContentManagement.Publishing" %><br/><br/></p></td></tr><tr><td><p><strong>3. </strong></p></td><td><p>Look for the <title></title> tags between the <Head> tags. Replace them with: <title><%= CmsHttpContext.Current.Posting.DisplayName %></title><br/><br/></p></td></tr><tr><td><p><strong>4. </strong></p></td><td>Below the <title> tag, add a tag to display the description of the posting:<br/><br/> <pre><meta name="Description" content="<%= CmsHttpContext.Current.Posting.Description %>"></pre><br/></td></tr><tr><td><p><strong>5. </strong></p></td><td><p>Save Columns.aspx.<br/><br/></p></td></tr></tbody></table> <p>When you next view a posting using the Columns template, you will see the DisplayName of the page in the browser’s title bar.</p> <p>To view the META tags, right-click on the page and select View Source. The Description META tag is nested between the <head> tags. You don’t get to see it displayed in the browser, as it is used solely for search engines as they index your site. The source should look like:</p> <pre><title>A Walk Through Jenny's Garden</title> <meta name="Description" content="You can publish pages directly from Word to MCMS using Authoring Connector!"> </pre><br/> <h2 id="pulling-meta-tag-content-from-custom-properties">Pulling META Tag Content from Custom Properties</h2> <p>Some META tags are more complex and can’t be generated by simply retrieving property values of postings. Say you have added a custom property called Keywords to every template object created. Authors enter keywords to describe the posting when they create it, which are then used for the custom property.</p> <p>In this section, we look at two alternatives for accessing that information. The first option we will explore is adding literal controls to the template files. In the second option we will create a user control to output the META tags.</p> <h3 id="using-literal-controls">Using Literal Controls</h3> <p>To pull content from custom properties, you could add a literal control between the <head> tags as shown below:</p> <pre><Head> <asp:Literal id="litKeywords" runat="server"></asp:Literal> . . . code continues . . . </Head></pre><br/> <p>Then, in the Page_Load() event handler of the code-behind file, you could retrieve the value of the custom property and insert it as the attribute of a <meta name="Keywords"> tag:</p> <pre>using Microsoft.ContentManagement.Publishing; ... code continues ... private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here Posting currentPosting = CmsHttpContext.Current.Posting; string keywords = ""; CustomProperty cpKeywords = currentPosting.CustomProperties["Keywords"]; if(cpKeywords!=null) { keywords = cpKeywords.Value; } litKeywords.Text = "<meta name=\"Keywords\" content=\"" + keywords + "\">"; } </pre><br/> <h3 id="overriding-the-render-method-of-a-web-user-control">Overriding the Render Method of a Web User Control</h3> <p>Here’s another approach: instead of using Literal controls within the <head> tags, you could create a web user control and override its Render() method. First get an instance of the posting, then get its custom property value, and finally create the META tag:</p> <pre>namespace TropicalGreen.UserControls { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; // MCMS PAPI using Microsoft.ContentManagement.Publishing; // Namespace for HtmlTextWriter using System.Web.UI; public abstract class MetaTags : System.Web.UI.UserControl { private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } protected override void Render( HtmlTextWriter writer ) { CmsHttpContext cmsContext = CmsHttpContext.Current; Posting p = cmsContext.Posting; string keywords = ""; CustomProperty cpKeywords = p.CustomProperties["Keywords"]; if (cpKeywords != null) { keywords = cpKeywords.Value; } writer.WriteLine("<meta name=\"keywords\" Content=\"" + keywords +"\">"); } #region Web Form Designer generated code . . . code continues . . . #endregion } } </pre><br/> <p>The MetaTags user control we have just created could also be enhanced to output the posting description and custom properties as META tags.</p> <p>You can use the same technique to add placeholder content to META tags. The MCMS Connector for SharePoint Technologies contains the customizable SearchMetaTagGenerator server control to generate META tags from properties and custom properties. </p></div><nav class="next" aria-label="More in this section"><a href="/windows-server/microsoft-content-management-server-influencing-search-engines-with-the-robots-meta-tag/" rel="prev"><span>← Previous</span>Microsoft Content Management Server : Influencing Search Engines with the ROBOTS META Tag</a><a href="/windows-server/sharepoint-2007-open-the-sites-settings-page-change-the-name-description-icon-or-url-of-a/" rel="next"><span>Next →</span>Sharepoint 2007 : Open the Site’s Settings Page & Change the Name, Description, Icon, or URL of a Site</a></nav></article><aside class="side" data-pagefind-ignore><div class="box rel"><h2>Related</h2><a href="/windows-server/microsoft-content-management-server-configuring-templates-to-allow-postings-to-return/">Microsoft Content Management Server : Configuring Templates to Allow Postings to Return Accurate Last Modified Time</a><a href="/windows-server/microsoft-content-management-server-copying-postings/">Microsoft Content Management Server : Copying Postings</a><a href="/windows-server/microsoft-content-management-server-implementing-server-side-validation/">Microsoft Content Management Server : Implementing Server-Side Validation</a><a href="/windows-server/microsoft-content-management-server-increasing-search-accuracy-by-generating-search/">Microsoft Content Management Server : Increasing Search Accuracy by Generating Search Engine Specific Pages</a><a href="/windows-server/microsoft-content-management-server-influencing-search-engines-with-the-robots-meta-tag/">Microsoft Content Management Server : Influencing Search Engines with the ROBOTS META Tag</a><a href="/windows-server/microsoft-content-management-server-managing-resources-part-2-replacing-resources/">Microsoft Content Management Server : Managing Resources (part 2) - Replacing Resources</a></div><div class="box"><h2>Section</h2><a href="/windows-server/">All Windows Server articles →</a></div></aside></div></div></main> <footer class="foot"> <div class="wrap"> <div class="cols"> <div> <a class="logo" href="/" style="color:#fff">programming<b>4</b>us</a> <p style="margin-top:14px;line-height:1.6">Tutorials, guides and tech news since 2010. More than 16,000 hands-on tutorials and guides.</p> </div> <div><h3>Windows</h3><ul><li><a href="/windows/">Windows</a></li><li><a href="/windows-7/">Windows 7</a></li><li><a href="/windows-vista/">Windows Vista</a></li><li><a href="/windows-xp/">Windows XP</a></li></ul></div><div><h3>Devices</h3><ul><li><a href="/desktop/">Desktop</a></li><li><a href="/laptop/">Laptop</a></li><li><a href="/mobile/">Mobile</a></li><li><a href="/camera/">Camera</a></li><li><a href="/hardware/">Hardware</a></li><li><a href="/imaging-devices/">Imaging Devices</a></li></ul></div><div><h3>Development</h3><ul><li><a href="/website/">Website</a></li><li><a href="/database/">Database</a></li><li><a href="/windows-azure/">Windows Azure</a></li><li><a href="/windows-phone/">Windows Phone</a></li></ul></div> <div><h3>Site</h3><ul> <li><a href="/news/">News</a></li><li><a href="/ai/">AI</a></li><li><a href="/social-media/">Social Media</a></li> <li><a href="/topics/">All topics</a></li><li><a href="/about/">About</a></li> <li><a href="/contact/">Contact</a></li><li><a href="/privacy/">Privacy policy</a></li><li><a href="/terms/">Terms</a></li> </ul></div> </div> <div class="legal"><span>© 2010–2026 Programming4us</span><span><a href="/sitemap-index.xml">Sitemap</a> · <a href="/rss.xml">RSS</a></span></div> </div> </footer> <script> document.querySelectorAll('.nav details').forEach(d=>{d.addEventListener('toggle',()=>{if(d.open){document.querySelectorAll('.nav details').forEach(o=>{if(o!==d)o.open=false});const r=d.querySelector('summary').getBoundingClientRect();const m=d.querySelector('.menu');m.style.left=Math.min(r.left,innerWidth-240)+'px';m.style.top=r.bottom+'px'}})}); document.addEventListener('click',e=>{if(!e.target.closest('.nav details'))document.querySelectorAll('.nav details[open]').forEach(d=>d.open=false)}); </script> <script>var sc_project=11388663;var sc_invisible=1;var sc_security="7db37af3";</script> <script async src="https://www.statcounter.com/counter/counter.js"></script> </body> </html>