Logo
CAR REVIEW
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Server

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

3/1/2012 6:13:26 PM
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 <title> tag and the Description and Keywords META tags.

In MCMS, channels and postings have Description and DisplayName properties, which are often suitable for the Description META tag and the <title> tag respectively.

Custom properties can also be used as META tags and rendered as <meta name="CustomPropertyName" content="CustomPropertyValue">


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.

There are several ways you can go about this:

  • The fastest method is to simply use <%= %> constructs or Response.Write() calls within the template HTML code.

  • If content that resides in custom properties or placeholders, you can retrieve it using code-behind files.

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.

Using <%= %> within Template Files

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.

1.
Open the Tropical Green project. Open the Columns.aspx template file in HTML view.

2.
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" %>

3.
Look for the <title></title> tags between the <Head> tags. Replace them with: <title><%= CmsHttpContext.Current.Posting.DisplayName %></title>

4.
Below the <title> tag, add a tag to display the description of the posting:

<meta name="Description" content="<%=
CmsHttpContext.Current.Posting.Description %>">

5.
Save Columns.aspx.

When you next view a posting using the Columns template, you will see the DisplayName of the page in the browser’s title bar.

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:

<title>A Walk Through Jenny's Garden</title>
<meta name="Description" content="You can publish pages directly from Word to
 MCMS using Authoring Connector!">

					  

Pulling META Tag Content from Custom Properties

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.

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.

Using Literal Controls

To pull content from custom properties, you could add a literal control between the <head> tags as shown below:

<Head>
  <asp:Literal id="litKeywords" runat="server"></asp:Literal>
  . . . code continues . . .
</Head>

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:

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 + "\">";
}

					  

Overriding the Render Method of a Web User Control

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:

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
  }
}

					  

The MetaTags user control we have just created could also be enhanced to output the posting description and custom properties as META tags.

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. 

Other -----------------
- Microsoft Content Management Server : Influencing Search Engines with the ROBOTS META Tag
- Windows Server 2003 : Recovering from System Failure (part 2) - Recovery Console
- Windows Server 2003 : Recovering from System Failure (part 1)
- Microsoft BizTalk 2010 : Consuming ASDK-based Adapters - The WCF-Custom adapter and SOAP actions
- Microsoft BizTalk 2010 : Consuming ASDK-based Adapters - Using the ASDK development tools
- Microsoft SQL Server 2008 R2 : SQL Server Management Studio - Administration Tools (part 2)
- Microsoft SQL Server 2008 R2 : SQL Server Management Studio - Administration Tools (part 1)
- Microsoft SQL Server 2008 R2 : SQL Server Management Studio - The Integrated Environment
- Managing Exchange Server 2010 Clients : Using Mail Profiles to Customize the Mail Environment
- Managing Exchange Server 2010 Clients : Managing the Exchange Server Configuration in Outlook
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 6) - WMI on Configuration Manager Servers
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 5) - The Configuration Manager Client WMI Namespace
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 4) - Hardware Inventory Through WMI
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 3) - Looking Inside the CIMV2 Namespace
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 2) - Managing WMI
- System Center Configuration Manager 2007 : Configuration Manager and WMI (part 1) - WMI Feature Set and Architecture
- System Center Configuration Manager 2007 : Active Directory Integration
- Deploying and Managing BizTalk Applications : Deploying a BizTalk Solution (part 2)
- Deploying and Managing BizTalk Applications : Deploying a BizTalk Solution (part 1) - Steps in Deploying a BizTalk Application
- Microsoft Dynamics CRM 4.0 Accelerators : Event Management Accelerator (part 3) - Publish the CRM Workflow & Testing the Portal
 
 
Most view of day
- Windows Phone 8 : Configuring Basic Device Settings - Screen Brightness (part 1) - Automatically Adjusting the Screen Brightness
- SQL Server 2012 : XML and the Relational Database - Shredding XML Using OPENXML
- Microsoft Exchange Server 2010 : Setting Up Transport Rules (part 1) - Transport Rules Coexistence Between Exchange 2007 and 2010 , Transport Rules and Server Design Decisions
- Windows Server 2003 : Protecting Hosts with Windows Host Firewalls - Firewall Basics
- Maintaining Windows 7 : Check Your Hard Drive for Errors
- Windows Server 2012 : Managing networking using Windows PowerShell (part 1) - Identifying networking cmdlets
- Microsoft Lync Server 2010 : Planning for Voice Deployment - Media Bypass
- Sharepoint 2013 : Service Application Administration (part 1) - Creating a New Instance of a Service Application
- Windows Phone 8 : Orientation and the PhoneApplicationPage Class (part 4) - Animating Page Elements When the Page Orientation Changes
- SQL Server 2008 R2 : Creating and Managing Stored Procedures - Debugging Stored Procedures Using SQL Server Management Studio
Top 10
- Microsoft Project 2010 : Linking Tasks (part 8) - Auditing Task Links,Using the Task Inspector
- Microsoft Project 2010 : Linking Tasks (part 7) - Creating Links by Using the Mouse,Working with Automatic Linking Options
- Microsoft Project 2010 : Linking Tasks (part 6) - Creating Links by Using the Entry Table
- Microsoft Project 2010 : Linking Tasks (part 5) - Creating Links by Using the Task Information Dialog Box
- Microsoft Project 2010 : Linking Tasks (part 4) - Entering Leads and Lags, Creating Links by Using the Menu or Toolbar
- Microsoft Project 2010 : Linking Tasks (part 3) - Using the Start-to-Start Relationship,Using the Finish-to-Finish Relationship
- Microsoft Project 2010 : Linking Tasks (part 2) - Using the Start-to-Start Relationship,Using the Finish-to-Finish Relationship
- Microsoft Project 2010 : Linking Tasks (part 1) - Defining Dependency Links
- Microsoft Project 2010 : Defining Task Logic - Manipulating Your Schedule
- Microsoft Lync Server 2013 : Director Troubleshooting (part 3) - Synthetic Transactions,Telnet
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro