Web design and hosting, database, cloud and social media solutions that deliver real business results
  • Servizi database
    • Strumenti
      • Backup del codice SQL
      • Claytabase Server Disk IOPs Calculator
      • Stampante SQL
    • Articoli tecnici
      • Piano di manutenzione di SQL Server 2008
      • Utilizzo dei dati di SQL Server
      • Utilizzo delle date di SQL Server
      • Utilizzo delle funzioni di SQL Server
      • Utilizzo di SQL Server Pivot-Unpivot
  • Sito Web Design
    • Articoli tecnici
      • ASP-NET
      • CSS
    • isola di Wight
    • Sicurezza del sito
  • Servizi per gli affari
    • Microsoft Azure
    • Microsoft Office
  • Circa
    • Portafoglio
    • Squadra
      • Chester Copperpot
CS - češtinaDE - DeutschEN - EnglishES - EspañolFR - FrançaisHI - हिंदीPL - polskiPT - PortuguêsRU - русскийTR - TürkZH - 中国的

Creazione di una Sitemap XML da SQL Server in ASP NET

Creazione di una Sitemap XML da SQL Server in ASP NET

Di

Ho voluto creare una mappa del sito per il mio sito web e ho deciso che XML era il miglior formato per i motori di ricerca da quello che ho potuto vedere su Wikipedia . Insieme a alcuni altri articoli che ho trovato sul web, mi metto in su con il codice qui sotto. Dovrebbe essere integrato senza problemi in un'applicazione con inclusione in un file robots.txt.

XML

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.claytabase.co.uk/en/About</loc>
    <lastmod>2013-12-13</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1</priority>
  </url>
  <url>
    <loc>https://www.claytabase.co.uk/en/Articles</loc>
    <lastmod>2013-12-09</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1</priority>
  </url>
</urlset>

Di

È molto simile al mio articolo RSS dove viene creato RSS XML in modo programmato e crea il relativo XML per te.

VB

Imports System.Data.SqlClient

Imports System.Xml

Imports System.Data

Imports System.Data.Sql

Partial Class SiteMap

    Inherits System.Web.UI.Page

    Dim con As New SqlConnection("{YourSQLConnection}")

    Private SubLoadFeed() Handles Me.Load

        Dim d As DateTime = DateTime.Now

       Response.Clear()

       Response.ContentType = "text/xml"

        Dim xtwFeed As XmlTextWriter = NewXmlTextWriter(Response.OutputStream, Encoding.UTF8)

       xtwFeed.WriartDocument()

 

       xtwFeed.WriartElement("urlset")

       xtwFeed.WriteAttriburing("xmlns","https://www.sitemaps.org/schemas/sitemap/0.9")

 

       xtwFeed.WriartElement("url")

       xtwFeed.WriteElementString("loc","https://www.domain.com/Home/")

       xtwFeed.WriteElementString("lastmod",String.Concat(d.ToString("yyyy-MM-dd")))

       xtwFeed.WriteElementString("changefreq","monthly") 'always, hourly, daily, weekly, monthly, yearly, never

       xtwFeed.WriteElementString("priority","1")

       xtwFeed.WriteEndElement()

       xtwFeed.WriartElement("url")

       xtwFeed.WriteElementString("loc","https://www.domain.com/About/")

       xtwFeed.WriteElementString("lastmod",String.Concat(d.ToString("yyyy-MM-dd")))

       xtwFeed.WriteElementString("changefreq","monthly")

       xtwFeed.WriteElementString("priority","1")

       xtwFeed.WriteEndElement()

       xtwFeed.WriartElement("url")

       xtwFeed.WriteElementString("loc","https://www.domain.com/Blog/")

       xtwFeed.WriteElementString("lastmod",String.Concat(d.ToString("yyyy-MM-dd")))

       xtwFeed.WriteElementString("changefreq","monthly")

       xtwFeed.WriteElementString("priority","1")

       xtwFeed.WriteEndElement()

       xtwFeed.WriartElement("url")

       xtwFeed.WriteElementString("loc","https://www.domain.com/WebDesign/")

       xtwFeed.WriteElementString("lastmod",String.Concat(d.ToString("yyyy-MM-dd")))

       xtwFeed.WriteElementString("changefreq","monthly")

        xtwFeed.WriteElementString("priority", "1")

       xtwFeed.WriteEndElement()

        Dim com As New SqlCommand("SELECT{YourLoc},{YourDateMod},{YourChangeFreq},{YourPriority} FROM{YourDatabase}", con)

       con.Open()

        Dim dr = com.ExecuteReader

        While dr.Read

           xtwFeed.WriartElement("url")

           xtwFeed.WriteElementString("loc","https://www.domain.com/Articles/afdasf/"+ dr.Item(0).ToString) 'OR full URL from yourdatabase!

           xtwFeed.WriteElementString("lastmod",String.Concat(dr.Item(1).ToString("yyyy-MM-dd"))) 'ISO1806format date.

           xtwFeed.WriteElementString("changefreq","monthly") 'Or dr.Item(2).ToString

           xtwFeed.WriteElementString("priority","0.5") 'Ordr.Item(3).ToString

            xtwFeed.WriteEndElement()

        End While

       dr.Close()

       con.Close()

       xtwFeed.WriteEndElement()

       xtwFeed.Flush()

       xtwFeed.Close()

       Response.End()

    End Sub

End Class

Helpful?

Please note, this commenting system is still in final testing.

Author

Gavin Clayton
Gavin Clayton
Ho formato Claytabase nel 2010 come un modo per continuare il mio lavoro con SQL Server e ASP.NET. Ciò è culminato nel sistema di gestione dei contenuti di Ousia che viene preso dal concetto a uno dei CMS più rapidi presenti sul mercato.
 Google Translate
Google Translate
RSS Login ContactCookie PolicyMappa del sito
facebook.com/Claytabaseinstagram.com/claytabase/twitter.com/Claytabaselinkedin.com/company/claytabase-ltd
+442392064871info@claytabase.co.ukGround Floor, Building 1000, Lakeside North Harbour, Western Road, Portsmouth, Hampshire, United Kingdom, PO6 3EZ
Partners
Le impostazioni di questo sito sono impostate per consentire tutti i cookie. Questi possono essere modificati sulla nostra pagina politica e le impostazioni dei cookie. Continuando a utilizzare questo sito l'utente accetta l'utilizzo dei cookie.
Ousia Logo
Ousia CMS Loader