问题描述
我想产生的一个特定的asp.net网站飞一个sitemap.xml的。
I'm trying to generate a sitemap.xml on the fly for a particular asp.net website.
我发现一对夫妇的解决方案:
I found a couple solutions:
- chinookwebs
- cervoproject
- newtonking
Chinookwebs是伟大的工作,但似乎有点不活跃,现在,它是不可能的,个性化的优先级和每一个每一个页面中的changefreq标记和,他们都继承自配置文件中的值相同。
Chinookwebs is working great but seems a bit inactive right now and it's impossible to personalize the "priority" and the "changefreq" tags of each and every page, they all inherit the same value from the config file.
做你们用什么办法呢?
非常感谢您的支持!
推荐答案
通常你会使用的这一点。给定一个要求......
Usually you'll use an HTTP Handler for this. Given a request for...
http://www.yoursite.com/sitemap.axd
...你的处理器将响应一个格式化XML网站地图。是否该站点地图上飞生成,从一个数据库,或一些其他的方法是达到HTTP处理程序实现。
...your handler will respond with a formatted XML sitemap. Whether that sitemap is generated on the fly, from a database, or some other method is up to the HTTP Handler implementation.
下面是它大概的样子:
void IHttpHandler.ProcessRequest(HttpContext context)
{
//
// Important to return qualified XML (text/xml) for sitemaps
//
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "text/xml";
//
// Create an XML writer
//
XmlTextWriter writer = new XmlTextWriter(context.Response.Output);
writer.WriteStartDocument();
writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
//
// Now add entries for individual pages..
//
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://www.codingthewheel.com");
// use W3 date format..
writer.WriteElementString("lastmod", postDate.ToString("yyyy-MM-dd"));
writer.WriteElementString("changefreq", "daily");
writer.WriteElementString("priority", "1.0");
writer.WriteEndElement();
//
// Close everything out and go home.
//
result.WriteEndElement();
result.WriteEndDocument();
writer.Flush();
}
这code可以改善但是这是基本的想法。
This code can be improved but that's the basic idea.
这篇关于生成网站地图上飞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!