|
Home Preview the Book Chapter 15, TOC Part 31
Previous:
Creating Web Pages on the Fly
Next:
Recap
Adding Meta-Keywords Dynamically
To improve your Web site’s ranking by search engines, you should carefully choose the keywords you provide in the head section of the HTML for each Web page. Your goal should be to include every word that might be entered by a potential visitor who is searching for sites like yours. When you build Web pages on the fly, you should consider adding pertinent meta-keywords on the fly. The code_browse page uses the u_keywords.ascx user control for precisely this purpose. The u_keywords.ascx file contain a single literal control, like this:
<asp:literal id="litKeywords" runat="server"></asp:literal>
The code behind the user control contains a static list of keywords that are applicable to every page in the site, and it exposes an Append property used to specify the word or words to add to the list. When the control is rendered, the static list and the appended word or words are included in a meta tag in the head section of the HTML. Listing 15-15 contains the code for this user control
Listing 15-15. The u_keywords.ascx.vb User Control Code
Public MustInherit Class u_keywords
Inherits System.Web.UI.UserControl
Protected WithEvents litKeywords As System.Web.UI.WebControls.Literal
[Designer generated code omitted]
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.litKeywords.Text = sMeta & _sAppend & sQuote & ">"
End Sub
Const sQuote As String = """"
Const sMeta As String = "<meta name=" & sQuote & "keywords" _
& sQuote & " content=" & sQuote _
& "code, sample code, example code, Web code, Web database, " _
& "Web database code, Visual Basic, Visual Basic .NET, " _
& "Visual Studio, Visual Studio .NET"
Private _sAppend As String
Property Append() As String
Get
Return _sAppend
End Get
Set(ByVal Value As String)
_sAppend = Value
End Set
End Property
End Class
To support the dynamic addition of keywords to the meta tag, the code_browse.aspx file contains this statement in the head section of its HTML:
<sma:keywords id="smaKey" runat="server"></sma:keywords>
The following code in the Page_Load procedure appends the current browse keyword to the static keywords rendered in the meta tag:
Dim ouKey As u_keywords
ouKey = CType(Me.FindControl("smaKey"), u_keywords)
ouKey.Append = ", " & sKeyword
This technique can also be used to modify other HTML elements that are not displayed in the browser window. As a matter of fact, the code_browse page modifies the title element on the fly, by incorporating the browse keyword into the title that’s displayed at the top of the browser.
Previous:
Creating Web Pages on the Fly
Next:
Recap
Home Preview the Book Chapter 15, TOC Part 31
|