View Single Post
  #2 (permalink)  
Old November 3rd, 2007, 02:07 PM
retroviz retroviz is offline
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just thought i would post my solution for this. SEO is a huge topic but i do believe these changes do make TBH more indexable.

[u]Page Titles</u>

Like many of you I aim to use the TBH structure for other websites. Currently all my content pages have their Title property set to "MyWebSiteName: PageName". I think this looks good but as the size of the site grows it will be a real pain if you then decide to name your site something different or use the same template for another site.

In addition to this (as already discussed), when I view different articles within my site, I don't want every one to have a page title of "MyWebSiteName: Show Article". I want it to appear as if they are viewing a completely different page in my website (rather than dynamically driven content from a database.

[u]META Description Attribute</u>

Similarly to the Title, I dont want every page to have the same "Decription" <meta> atttibute. Many search engines use the description data when showing search results. If there is a link to a page regarding a specific product, I do not want my description to show as "Welcome to MyWebSite.com, on this site we do all sorts....". I want it to be associated with the page being displayed.

[u]Solution</u>

First thing was to add 2 new properties to my custom configuration section in Web.Config:

Code:
  <retroWebSection defaultConnectionStringName="LocalSqlServer" webSiteName="MyWebsite.Com" 
                   webSiteDescription="Some description">


Then I added 2 new properties to my RetroWebSection Class in App_Code/ConfigSection.vb.
I set a default value for the PageTitle property so that if one was ommitted from web.config I can show the name of my template:

Code:
        <ConfigurationProperty("webSiteName", DefaultValue:="RetroViz.Cms")> _
        Public Property WebSiteName() As String
            Get
                Return CStr(Me("webSiteName"))
            End Get
            Set(ByVal value As String)
                Me("webSiteName") = value
            End Set
        End Property

        <ConfigurationProperty("webSiteDescription")> _
        Public Property WebSiteDescription() As String
            Get
                Return CStr(Me("webSiteDescription"))
            End Get
            Set(ByVal value As String)
                Me("webSiteDescription") = value
            End Set
        End Property


Once added I can access both properties (or values from web.config) from

Code:
Globals.Setting.WebSiteName
Globals.Settings.WebSiteDescription
Fairly simple :D

Now I needed to dynamically add the title and description attributes when required. One thing I took into consideration is that I only really wanted to override the Page Title property on my ShowArticles.aspx?.. pages so needed some way of preserving the Title values for other pages.

I decided to add a MasterBasePage class (similar to BasePage) that my MasterPage.Master page can inherit from. In there I defined two public properties for PageTitle and PageDescription that can be accessed by my ContentPages as well as the code to dynamically change some <meta> tags in the head of the page:

Code:
Imports Microsoft.VisualBasic
Namespace Retro.Web.UI
    Public Class MasterBasePage
        Inherits System.Web.UI.MasterPage

        Private _pageTitle As String
        Private _pageDescription As String

        Public Property PageTitle() As String
            Get
                PageTitle = _pageTitle
            End Get
            Set(ByVal value As String)
                _pageTitle = value
            End Set
        End Property

        Public Property PageDescription() As String
            Get
                PageDescription = _pageDescription
            End Get
            Set(ByVal value As String)
                _pageDescription = value
            End Set
        End Property

        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            If String.IsNullOrEmpty(PageTitle) Then
                _pageTitle = Me.Page.Title
            End If
            If String.IsNullOrEmpty(PageDescription) Then
                _pageDescription = Globals.Settings.WebSiteDescription
            End If
            Me.Page.Title = Globals.Settings.WebSiteName + ": " + _pageTitle
            Dim metaTag As HtmlMeta = New HtmlMeta()
            metaTag.Name = "Description"
            metaTag.Content = _pageDescription
            Page.Header.Controls.Add(metaTag)

            MyBase.OnLoad(e)
        End Sub
    End Class
End Namespace
Then in the code behind for my MasterPage:

Code:
Namespace Retro.Web.UI
    Partial Class MasterPage
        Inherits MasterBasePage
    End Class
End Namespace
And thats it.

If I load my Default.aspx I get my website name and the Title property set in the ContentPage definition i.e. "MyWebSite.Com: Home". If I view the source for the page I can see the Description META information is the text set in my web.config file.

For my Article pages, I first need to add the following to the top of my ShowArticles.aspx page to allow the MasterPage properties to be accessed:

Code:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
Then I can add the following to Page_Load event:

Code:
                Master.PageTitle = article.Title
                Master.PageDescription = article.Abstract


Now when I re index with Zoom Search, not only do I get a title that relates to the actual article, but also the related description from the Abstract field of that record.

Quote:
quote:100 results found.


10 pages of results.
21. MyWebSite.Com: Launch of new website!
MyWebSite.com has been completely revamped. Our new site will help you to find the pump application you require and give you access to online s...
Simple as that. If anyone has any further suggestions or improvements that could/should be made then please do comment. It's in VB.net so you may want to translate if working with the C# version. My namespaces are the same as TBH but its Retro.Web.UI instead of MB.TheBeerHouse.UI (and so on and so forth)

Thanks,