http://www.mikesdotnetting.com/Article/111/-MVC-with-LINQ-To-XML
MVC 3.0 创建 Sitemap.xml and Rss
转载http:///support/webmasters/bin/answer.py?answer=183668 --sitemap format
FunnyDataContext context = new FunnyDataContext();
public ContentResult Sitemap()
{
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
const string url = "http://www.suhow.com/Video/Detail?title={0}";
var list = context.Videos.ToList();
var sitemap = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "urlset",
from item in list
select
new XElement("url",
new XElement("loc", string.Format(url, item.Title)),
new XElement("lastmod", String.Format("{0:yyyy-MM-dd}", item.CreateTime)),
new XElement("changefreq", "monthly"),
new XElement("priority", "0.5"))));
return Content(sitemap.ToString(), "text/xml");
}
public ContentResult Rss()
{
const string url = "http://www.suhow.com/Video/Detail?title={0}";
var list = context.Videos.ToList();
var rss = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement("rss",
new XAttribute("version", "2.0"),
new XElement("channel",
new XElement("title", "Suhow Feed"),
new XElement("link", "http://www.suhow.com/rss"),
new XElement("description", "Funny,joke,twitter,video,picture,quotains"),
new XElement("copyright", "(c)" + DateTime.Now.Year + ", Suhow. All rights reserved"),
from item in list
select
new XElement("item",
new XElement("title", item.Title),
new XElement("description", item.Description),
new XElement("link", String.Format(url, item.Title)),
new XElement("pubDate", item.CreateTime.ToString("R"))
)
)
)
);
return Content(rss.ToString(), "text/xml");
}
Finally,using /xml/sitemap to browse sitemap.xml
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【Docker项目实战】使用Docker部署RSS阅读器fusion
【Docker项目实战】使用Docker部署RSS阅读器fusion
docker Docker bash -
Python:使用sitemap库生成网站地图文件sitemap.xml
可以使用sitemap库生成网站地图文件sitemap.xml文档安装。
python xml 开发语言 github -
前端 Website 的 sitemap.xml 文件和搜索引擎优化
结果中的排名。 Si
搜索引擎 xml 优先级 -
Hexo 入门指南(六) - sitemap、rss 和部署
sitemap & rss切换到blog根目录下,输入:$ npm install hexo-generator-feed$ npm in
hexo node.js 静态博客 git xml -
提交网站地图创建Google网站地图Sitemap.xml
最近个人几篇文章介绍了改提交网站地图的文章. 关联文章的地址Sitemap.xml
xml 搜索 转义字符 xml文件 搜索引擎
















