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
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...).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
Oh and the xml file looks like this:
Any pointers, direction, etc is appreciated!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>
Thanks!
D




Reply With Quote