SiteMap.cs :  » Bloggers » BlogEngine.NET » BlogEngine.Core » Web » HttpHandlers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » BlogEngine.NET 
BlogEngine.NET » BlogEngine.Core » Web » HttpHandlers » SiteMap.cs
#region Using

using System;
using System.Xml;
using System.Web;
using BlogEngine.Core;

#endregion

namespace BlogEngine.Core.Web.HttpHandlers{
  /// <summary>
  /// A blog sitemap suitable for Google Sitemap as well as
  /// other big search engines such as MSN/Live, Yahoo and Ask.
  /// </summary>
  public class SiteMap : IHttpHandler
  {

    /// <summary>
    /// Enables processing of HTTP Web requests by a custom HttpHandler that 
    /// implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
    /// </summary>
    /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> 
    /// object that provides references to the intrinsic server objects 
    /// (for example, Request, Response, Session, and Server) used to service HTTP requests.
    /// </param>
    public void ProcessRequest(HttpContext context)
    {
      using (XmlWriter writer = XmlWriter.Create(context.Response.OutputStream))
      {
        writer.WriteStartElement("urlset", "http://www.google.com/schemas/sitemap/0.84");

        // Posts
        foreach (Post post in Post.Posts)
        {
                    if (post.IsVisibleToPublic)
          {
            writer.WriteStartElement("url");
            writer.WriteElementString("loc", post.AbsoluteLink.ToString());
            writer.WriteElementString("lastmod", post.DateModified.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
            writer.WriteElementString("changefreq", "monthly");
            writer.WriteEndElement();
          }
        }

        // Pages
        foreach (Page page in Page.Pages)
        {
          if (page.IsVisibleToPublic)
          {
            writer.WriteStartElement("url");
            writer.WriteElementString("loc", page.AbsoluteLink.ToString());
            writer.WriteElementString("lastmod", page.DateModified.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
            writer.WriteElementString("changefreq", "monthly");
            writer.WriteEndElement();
          }
        }

        // Removed for SEO reasons
        //// Archive
        //writer.WriteStartElement("url");
        //writer.WriteElementString("loc", Utils.AbsoluteWebRoot.ToString() + "archive.aspx");
        //writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        //writer.WriteElementString("changefreq", "daily");
        //writer.WriteEndElement();

        // Contact
        writer.WriteStartElement("url");
        writer.WriteElementString("loc", Utils.AbsoluteWebRoot.ToString() + "contact.aspx");
        writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
        writer.WriteElementString("changefreq", "monthly");
        writer.WriteEndElement();

        // Blog
        if (Page.GetFrontPage() != null)
        {
          writer.WriteStartElement("url");
          writer.WriteElementString("loc", Utils.AbsoluteWebRoot.ToString() + "blog.aspx");
          writer.WriteElementString("lastmod", DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
          writer.WriteElementString("changefreq", "daily");
          writer.WriteEndElement();
        }

        writer.WriteEndElement();
      }

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

    /// <summary>
    /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler"></see> instance.
    /// </summary>
    /// <value></value>
    /// <returns>true if the <see cref="T:System.Web.IHttpHandler"></see> instance is reusable; otherwise, false.</returns>
    public bool IsReusable
    {
      get { return false; }
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.