locked
How do I download and apply metatag and title information created and stored in Access RRS feed

  • Question

  • User-1746945187 posted

    For the simple ad hoc CMS I'm experimenting with, I'm trying to create and store the page title, and description and keyword metatag data in Access2000, then apply them to pages (several hundred of them), using SELECT statements based on the page url.  I'm using VB, and master pages.  With huge help from others in this forum I have so far set up datasources that supply page content, in the form:

    [<script>]
    Sub
    SelectByPageUrl(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
    e.Command.Parameters(
    "pageurl").Value = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.ToString()
    End Sub
    [</script>]

    [<body>]
    <asp:AccessDataSource ID="srcPageData" runat="server" DataFile="\App_Data\web.mdb"
      SelectCommand="SELECT [pageurl], [field1], [field2] FROM [qryQuery] WHERE ([pageurl] = ?)" OnSelecting="SharedSelectByPageUrl.SelectByPageUrl">
       <SelectParameters>
          <asp:Parameter Name="pageurl" Type="String" />
       </SelectParameters>
    </asp:AccessDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="srcPageData">
      <Fields>
         <asp:BoundField DataField="pageurl" />
         <asp:BoundField DataField="field1" />
         <asp:BoundField DataField="field2" />
         </Fields>
    </asp:DetailsView>
    [</body>]

    I have found a very helpful post that shows how to stuff the header metatags (located in master pages) from the content page: http://forums.asp.net/thread/1606240.aspx.  (And what about the Page Title?)

    Now I need to combine these two ideas, but being a newbie I'm well over my boots.  I think the question is "how do you stuff the data retrieved by SelectCommand into Htmlmeta controls and the page title?" This may be trivial to some, but I'm missing some pieces of the jigsaw! 

    Many thanks for any help - especially if spelled out!!

    Thursday, April 26, 2007 6:59 AM

Answers

All replies

  • User-821857111 posted

    This should help you:

    http://aspnet.4guysfromrolla.com/articles/041107-1.aspx.

    To set the page title is simply Page.Title = "some string".  Make sure that the default <title>Untitled Page</title> is removed first.
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 27, 2007 7:51 AM
  • User-1746945187 posted

    Thanks again Mike!  Very helpful, as ever. I'm stuck on the keywords now!

    So far I've got the page title and description sorted:

    <script>
    'Code that generates the url of the current page for use in SQL OnSelecting
    Protected Sub SelectByPageUrl(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
       e.Command.Parameters(
    "pageurl").Value = Request.AppRelativeCurrentExecutionFilePath.ToString()
    End Sub

    'Code to emit the title and description data into the header
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       Dim dv As Data.DataView
       dv =
    CType(srcPageHeader.Select(DataSourceSelectArguments.Empty), Data.DataView)
       Dim dr As Data.DataRowView = dv(0)
       Dim thetitle As String = CStr(dr("title"))
       Page.Header.Title = thetitle

       Dim metaDescription As New HtmlMeta
       Dim thedescription As String = CStr(dr("description"))
       metaDescription.Name = "Description"
       metaDescription.Content = thedescription
       Page.Header.Controls.Add(metaDescription)

    End Sub
    </script>

    <body>
    <asp:AccessDataSource ID="srcPageHeader" runat="server" DataFile="~/App_Data/web.mdb"
    SelectCommand="SELECT [pageurl], [title], [description] FROM [qryPages] WHERE ([pageurl] = ?)" OnSelecting="SelectByPageUrl">
    <SelectParameters>
    <asp:Parameter Name="pageurl" Type="String" />
    </SelectParameters>
    </asp:AccessDataSource>
    </body>

    But the SQL statement for the keywords will produce a 1 x n table of keywords which will have to be concatenated into a single string (and separated with commas). So I suppose I need something like this:

       Dim metaDescription As New HtmlMeta
       Dim thekeywords As String

       Dim rstRows As Value
       rstRows = [function that returns the number of rows in the recordset returned by the SQL statement]
       [Loop through the rows and concatenate into 'thekeywords']
       thekeywords=
    CStr(dr("keywords"))
       metaDescription.Name = "Keywords"
       metaDescription.Content = the keywords
       Page.Header.Controls.Add(metaDescription)

    Hmm...!  Any ideas?

    Saturday, April 28, 2007 2:05 PM
  • User-821857111 posted

    Do While (dr.Read())
        thekeyword += dr("keywords")
    Loop

     

    Saturday, April 28, 2007 2:22 PM
  • User-1746945187 posted

    Thanks again!  Everything's working.  Here's the code: 

    <%@ Page Language="VB" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    script runat="server">
    'Collect pageurl for use as parameter in 'SelectCommand' in AccessDataSources
    Protected Sub SelectByPageUrl(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
    e.Command.Parameters(
    "pageurl").Value = Request.AppRelativeCurrentExecutionFilePath.ToString()
    End Sub
    'Set the page title and the 'description' and 'keywords' metatags
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    'Page title property
    Dim dvTitleDescription As Data.DataView
    dvTitleDescription =
    CType(srcTitleDescription.Select(DataSourceSelectArguments.Empty), Data.DataView)
    Dim drTitleDescription As Data.DataRowView = dvTitleDescription(0)
    Dim theTitle As String = CStr(drTitleDescription("title"))
    Page.Header.Title = theTitle
    'Description metatag
    Dim theDescription As String = CStr(drTitleDescription("description"))
    Dim metaDescription As New HtmlMeta
    metaDescription.Name =
    "description"
    metaDescription.Content = theDescription
    Page.Header.Controls.Add(metaDescription)
    'Keywords metatag
    'Get keywords as a DataView
    Dim theKeywords As String
    theKeywords = ""
    Dim vwKeywords As System.Data.DataView = CType(srcKeywords.Select(DataSourceSelectArguments.Empty), System.Data.DataView)
    'Loop through each record
    For Each rowKeyword As System.Data.DataRowView In vwKeywords
    'Concatenate the keywords into a single string
    theKeywords &= String.Format("{0}; ", rowKeyword("Keyword"))
    Next
    'Create the metatag and apply the concatenated string to it
    Dim metaKeywords As New HtmlMeta
    metaKeywords.Name =
    "keywords"
    metaKeywords.Content = theKeywords
    Page.Header.Controls.Add(metaKeywords)
    End Sub
    </script>
    <
    html xmlns="http://www.w3.org/1999/xhtml" >
    <
    head runat="server">
    <title>Untitled Page</title>
    </
    head>
    <
    body>
    <form id="form1" runat="server">
    <div>
    <asp:AccessDataSource ID="srcTitleDescription" runat="server" DataFile="~/App_Data/web.mdb"
    SelectCommand="SELECT [pageurl], [title], [description] FROM [qryPages] WHERE ([pageurl] = ?)" OnSelecting="SelectByPageUrl">
    <SelectParameters>
    <asp:Parameter Name="pageurl" Type="String" />
    </SelectParameters>
    </asp:AccessDataSource>
    <asp:AccessDataSource ID="srcKeywords" runat="server" DataFile="~/App_Data/web.mdb"
    SelectCommand="SELECT [pageurl], [keyword] FROM [qryKeywords] WHERE ([pageurl] = ?)" OnSelecting="SelectByPageUrl">
    <SelectParameters>
    <asp:Parameter Name="pageurl" Type="String" />
    </SelectParameters>
    </asp:AccessDataSource>
    </div>
    </form>
    </
    body>
    </
    html>

    Incidentally, I omitted to remove the default title tag in the page content but it seems to work fine anyway.

    Phase 2 completed.  Very many thanks for your help!!!

    Monday, April 30, 2007 4:53 AM
  • User-1029334460 posted

    Can you please share the code written behind the "drTitleDescription("description"))"  the drTitleDescription function. I am stucked their please help me out.


    My Code : 

     'Dim metaTag As HtmlMeta = New HtmlMeta()
                    '    'metaTag.ID = controlID
                    '    'metaTag.Name = "Description"
                    '    'metaTag.Content = Me.Description 'this is harder
                    '    'Me.Header.Controls.Add(metaTag)
                    'End If


     'Dim metaTag As HtmlMeta = New HtmlMeta()

                       'metaTag.ID = controlID

                       'metaTag.Name = "Description"

                       'metaTag.Content = Me.Description 'this is harder

                       'Me.Header.Controls.Add(metaTag)

                    'End If


    in your code :

     Dim theDescription As String = CStr(drTitleDescription("description"))

                    Dim metaDescription As New HtmlMeta

                    metaDescription.Name = "description"

                    metaDescription.Content = theDescription

                    Page.Header.Controls.Add(metaDescription)


    theDescription get value that is returned from DrTitleDescription ("description")


    Please share the code you had written behind this function 

    Tuesday, September 14, 2010 5:55 PM