MarkItUp.SingleUserBlog.Web/GSitemap.ashx

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<%@ WebHandler Language="C#" Class="GSitemap" %>

//Original code from: http://www.gotdotnet.com/codegallery/codegallery.aspx?id=237330e0-65c5-4ebb-b62b-e486dd598604

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Web;
using System.Xml;
using MarkItUp.SingleUserBlog.Services;

public class GSitemap : IHttpHandler {
    private const int MaxDepth = 6;
    
    public void ProcessRequest (HttpContext context) {
        HttpResponse response = context.Response;
        response.ContentType = "text/xml";

        using (XmlTextWriter writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8)) {
            writer.Formatting = Formatting.Indented;
            writer.WriteStartDocument();
            writer.WriteStartElement("urlset");
            writer.WriteAttributeString("xmlns", "http://www.google.com/schemas/sitemap/0.84");
            SiteMapNode root = SiteMap.RootNode;
            WriteNode(root, writer, 0);
            WritePosts(DataLayer.Instance.ListPostsByAll(),writer);
            WriteCategories(DataLayer.Instance.ListCategories(), writer);
            writer.WriteEndElement(); // urlset
            writer.WriteEndDocument();
        }
    }
 
    public bool IsReusable {
        get {
            return true;
        }
    }

    private void WriteCategories(CategoryCollection categories, XmlTextWriter writer)
    {
        foreach (Category c in categories)
        {
            writer.WriteStartElement("url");
            writer.WriteElementString("loc", MarkItUp.SingleUserBlog.Common.Globals.UrlStartPath+"Posts/PostsByCategory.aspx?categoryId="+c.Id);
            writer.WriteEndElement(); // url
        }
    }
    
    private void WritePosts(PostCollection posts, XmlTextWriter writer)
    {
		foreach(Post p in posts)
		{
		writer.WriteStartElement("url");
			writer.WriteElementString("loc", MarkItUp.SingleUserBlog.UI.UrlFormatter.FormatUri(p));
			writer.WriteElementString("lastmod", p.DateModified.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss.fffZ"));
			writer.WriteEndElement(); // url
		}
    }

后面还有 62 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。