我的网站有动态内容,正在创建新链接。
我的数据库有一个表,它几乎包含了所有添加的URL。
所以我的问题是如何使用sitemaps.xml来获取importnt,还有一种简单的方法来构建它,以便在生成新链接时我可以将它标记到sitemap.xml文件的末尾吗?
答案 0 :(得分:2)
抓取工具能够更快,更准确地抓取您的网站非常重要。
你可以创建一个控制器,比如siteMapController,并在索引中添加以下内容
public ActionResult Index() {
var xmlString =
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";
xmlString +=
"<url>" +
"<loc>Your site</loc>" +
"<changefreq>weekly</changefreq>" +
"<priority>0.6</priority>" +
"</url>" +
"<url>" +
"<loc>Static Link of you site</loc>" + //you can add as many you want
"<changefreq>weekly</changefreq>" +
"<priority>0.6</priority>" +
"</url>" +
"<url>";
//Dynamic links
xmlString += "<url>" +
"<loc>Link of new item"</loc>" +
"<lastmod>" + DateTime.Now.ToString("yyyy-MM-dd") + "</lastmod>" +
"<changefreq>daily</changefreq>" +
"<priority>0.8</priority>" +
"</url>";
}
xmlString += "</urlset>";
ViewData["siteMap"] = xmlString;
return View();
}
将xml保存在您的服务器上,并通过此链接发布站点地图
https://www.google.com/webmasters/tools/home?hl=en
希望有所帮助
答案 1 :(得分:2)
您可以使用LINQ to XML从数据库创建XML站点地图,然后通过返回Content(document.ToString(), "text/xml")
从操作返回站点地图。