为我的网站自动生成 sitemap.xml

发布于 2024-10-01 05:52:50 字数 54 浏览 0 评论 0 原文

有人可以指导我如何使用 ashx 处理程序为我的网站自动生成 sitemap.xml 文件吗?

Can anybody please guide me on how to auto generate a sitemap.xml file for my website using an ashx handler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2024-10-08 05:52:50

假设您网站上的每个唯一的 aspx 文件都对应一个页面,您将需要使用 System.IO*.aspx 命名空间过滤。如果您提供 *.html*.pdf 等,您可能希望包含其他可能的文件。

创建一个递归函数,迭代目录中的所有文件,然后调用本身位于目录中的所有子目录上。

当您浏览目录树时,只需在 sitemap.xml 中为每个项目生成一个节点。使用 String.Builder 执行此操作。

您的 sitemap.xml 结构 是;

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset> 

将 URL 附加到单独的 元素中。

Assuming that each unique aspx file on your site corresponds to a single page you will want to traverse the files and the folders within your site using the Directory objects in System.IO namespace filtering for *.aspx. You may want to include other possible files if you serve *.html or *.pdf etc.

Create a recursive function that iterates through all the files in a directory and then calls itself on all the subdirectories in the directory.

As you walk the directory tree simply generate a node in sitemap.xml for each item. Do this with String.Builder.

Your sitemap.xml structure is;

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2005-01-01</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset> 

Append the URLs in separate <loc/> elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文