Web design and hosting, database, cloud and social media solutions that deliver real business results
  • 数据库咨询服务
    • 报告
      • Claytabase Server Disk IOPs Calculator
      • SQL代码备份
      • SQL打印机
    • 技术文章
      • SQL-Server
      • SQL Server 2008的维护计划
      • 使用SQL Server函数
      • 使用SQL Server日期
      • 使用SQL Server透视-取消透视
  • 网站设计
    • 怀特岛
    • 技术文章
      • ASP-NET
      • CSS
    • 网站安全
  • 产品展示
  • 社交媒体
  • 关于我们
    • 投资组合
    • 球队
      • 切斯特Copperpot
CS - češtinaDE - DeutschEN - EnglishES - EspañolFR - FrançaisHI - हिंदीIT - italianoPL - polskiPT - PortuguêsRU - русскийTR - Türk

在ASP.NET中从SQL Server创建XML Sitemap

在ASP.NET中从SQL Server创建XML Sitemap

关于

我想为我的网站创建一个网站地图,并且决定XML是从维基百科可以看到的搜索引擎的最佳格式。随着我在网络上发现的其他一些文章,我可以看到下面的代码。它应该可以无缝集成到一个包含在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>

关于

它与我的RSS文章非常相似, RSS文章以编程方式创建,并为您创建相关的XML。

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
I formed Claytabase in 2010 as a way of carrying on my work with SQL Server and ASP.NET. This has culminated in the Ousia Content Management System being taken from concept to one of the quickest CMS's on the market.
 Google Translate
Google Translate
RSS Login ContactCookie政策网站地图
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
此网站上的设置设置为允许所有Cookie。 这些可以在我们的Cookie政策和设置页面上更改。继续使用本网站即表示您同意使用Cookie。
Ousia Logo
Ousia CMS Loader