Results 1 to 4 of 4

Thread: [2005] Help with meta content

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    [2005] Help with meta content

    Hello all, I am journeying into ASP.net to create my own website. I am trying to start with a master page and some content pages. My question right now is that I am trying to implement some search engine friendly stuff to the website and am using the code found at the very bottom of this msdn article. I translated it into vb.net
    Code:
    Public Sub SetMetaContent()
            Dim pageDefault As String = ConfigurationManager.AppSettings("defaultPage").ToString()
            Dim doc1 As XmlDocument
    
            If Cache("PageXml") Is Nothing Then
                doc1 = New XmlDocument()
                doc1.Load(Server.MapPath("App_Data\xmlSiteDesc.xml"))
    
                'xml document added to cache and set its cache dependency to file dependency// note: Keep Xml File in App_Data folder for Security reasons. 
                Cache.Insert("PageXml", doc1, New System.Web.Caching.CacheDependency(Server.MapPath("App_Data\xmlSiteDesc.xml")))
            Else
                doc1 = DirectCast(Cache("PageXml"), XmlDocument)
            End If
    
            Dim xpathNav As XPathNavigator = doc1.CreateNavigator()
    
            'Compile the XPath expression 
            Dim xpathExpr As XPathExpression = xpathNav.Compile("/Pages/Page[PageName='" & Request.Path.ToString().Replace("/", "").Trim().ToLower() & "']")
            Dim nodeIter As XPathNodeIterator = xpathNav.[Select](xpathExpr)
    
            ' if page information not found in xml file use default page title, keyword and description 
            If nodeIter.Count = 0 Then
                xpathExpr = xpathNav.Compile("/Pages/Page[PageName='" & pageDefault.Trim().ToLower() & "']")
                nodeIter = xpathNav.[Select](xpathExpr)
            End If
    
            While nodeIter.MoveNext()
                xpathNav = nodeIter.Current
    
                If xpathNav.MoveToFirstChild() Then
                    Do
                        Select Case xpathNav.Name.ToUpper()
    
                            Case "TITLE"
                                metaTitle.Text = HttpUtility.HtmlEncode(xpathNav.Value)
    
                            Case "DESCRIPTION"
                                metaDesc.Content = HttpUtility.HtmlEncode(xpathNav.Value)
    
                            Case "KEYWORDS"
                                metaKeyword.Content = HttpUtility.HtmlEncode(xpathNav.Value)
    
                        End Select
                    Loop While (xpathNav.MoveToNext())
                End If
            End While
        End Sub
    The Content XML Page I have created is in the App_Data directory and is called "xmSiteDesc.xml". Did I set this up right and replace the right areas? Due to IIS issues on this particular machine, I cannot exactly test it (I keep getting Error 505...).

    Oh and the xml file looks like this:
    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
    <Pages>
      <Page>
        <!-- your page title -->
        <Title>Welcome to Shore Technical</Title>
        <!-- your .aspx file name for example -->
        <PageName>default.aspx</PageName>
        <!-- your page description  -->
        <description>Home Page for Shore Technical</description>
        <keywords>Software development visual basic vb.net custom programming programmer</keywords>
        <COPYRIGHT>Shore Technical</COPYRIGHT>
        <GENERATOR>Shore Techincal Generator</GENERATOR>
        <AUTHOR>Shore Technical</AUTHOR>
      </Page>
    </Pages>
    Any pointers, direction, etc is appreciated!


    Thanks!

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] Help with meta content

    Another issue I am having with the Master page that I cannot seem to figure out is that when I have a content area identified in the MasterPage:
    Code:
         <div id="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
                The Main Content is not available, sorry for the inconvenience.
            </asp:ContentPlaceHolder> 
         </div>
    and the content identified in default2.aspx:
    Code:
    <%@ Page Language="VB" MasterPageFile="~/MyMasterPage.master" AutoEventWireup="false" 
        CodeFile="Default2.aspx.vb" Inherits="Default2" title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    Showing you the Main Content now baby!!
    </asp:Content>
    It does not show up in the MasterPage. Am I doing something wrong??

    Finally, I have a .css file that I want to use and it is again not showing up on the Masterpage:
    Code:
    <head runat="server">
            <title id="metaTitle" runat="server"></title>    
            <meta name="metaDesc" content="description" id="metaDesc" runat="server" />    
            <meta name="metaKeyword" content="keys" id="metaKeyword" runat="server" />
            <link href="~/Style.css" rel="Stylesheet" type="text/css" />
    </head>
    The css file is in the same directory as the masterpage but it does not apply it. I am trying to do right, but cannot seem to do right.....HELP!!!

    Thanks,

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Help with meta content

    The App_Data folder is not meant for anything but MDB or MDF files. Move your XML file out and put it into somet other folder.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Help with meta content

    Also, I don't think you can use ~ in non-server side tags. You'll need to use a normal path like /blah/clah.css.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width