技术开发 频道

详解ASP.NET的SEO:Linq to XML打造地图

  同样还将使用到xml技术的还有RSS

  RSS

  using System;

  
using System.Web;

  
using System.Xml;

  
using System.Xml.Linq;

  
public class rss : IHttpHandler {

  
public void ProcessRequest (HttpContext context) {

  context.Response.ContentType
= "text/xml";

  context.Response.Write(
"");

  XElement rssFeed
= new XElement("rss", new XAttribute("version","2.0"));

  
string fixedUrl = "http://www.freeflying.com/article";

  
string wholeUrl = string.Empty;

  XElement channel
= new XElement("channel",

  
new XElement("title", "freeflying"),

  
new XElement("link", fixedUrl),

  
new XElement("description","the website for dream flying freely"),

  
new XElement("pubDate",DateTime.Now.ToString())

  );

  
foreach (var article in Articles.GetArticles())

  {

  XElement item
= new XElement("item");

  XElement title
= new XElement("title", article.Title);

  wholeUrl
= string.Format("{0}?id={1}&catelog={2}", fixedUrl, article.ID, article.Catelog);

  XElement link
= new XElement("link", wholeUrl);

  XElement description
= new XElement("description", article.Description);

  XElement pubDate
= new XElement("pubDate", article.LastMod.ToString());

  item.Add(title,link,description,pubDate);

  channel.Add(item);

  }

  rssFeed.Add(channel);

  context.Response.Write(rssFeed);

  }

  
public bool IsReusable {

  
get {

  
return false;

  }

  }

  }

 

0
相关文章