guest
2012-10-02T18:14:29Z
Hi,

I am using YetAnotherforum for my forum. Thanks for excellent software.

Can any one help me how to create site map for YetANotherforum forum.

Thanks & Regards,
John
Sponsor
bbobb
  •  bbobb
  • 100% (Exalted)
  • YAF Developer
2012-10-02T19:41:02Z
Just an example how to make it simple.

1. Create the file here /Classes/SitemapHandler.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Xml;
using YAF.Classes.Data;
using YAF.Core;
using YAF.Types.Constants;
using YAF.Utils;

namespace YAF
{
    public class SitemapHandler : IHttpHandler
    {
        protected enum ChangeFrequency
        {
            always,
            hourly,
            daily,
            weekly,
            monthly,
            yearly,
            never
        }

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return false; }
        }

        public void ProcessRequest(HttpContext context)
        {
 if (context.Request.UrlReferrer == null ||
                !context.Request.UrlReferrer.AbsoluteUri.Contains(BaseUrlBuilder.BaseUrl)) return;

            using (TextWriter textWriter = new StreamWriter(context.Response.OutputStream, System.Text.Encoding.UTF8))
            {
                var writer = new XmlTextWriter(textWriter) {Formatting = Formatting.Indented};
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset");
                writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                writer.WriteAttributeString("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1");
                writer.WriteAttributeString("xmlns:video", "http://www.google.com/schemas/sitemap-video/1.1");

                // Add home page
                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://forum.yetanotherforum.net/");
                writer.WriteElementString("lastmod",
                                          DateTime.Now.ToString("yyy-MM-dd",
                                                                System.Globalization.CultureInfo.InvariantCulture));
                writer.WriteElementString("changefreq", ChangeFrequency.always.ToString());
                writer.WriteElementString("priority", "0.8");
                writer.WriteEndElement(); // url

                //  Forums here 1-  boardid, 10 - a number of forum links.
               var dt = LegacyDb.forum_simplelist(1,10);
               foreach (DataRow drow in dt.Rows)
                {
                    writer.WriteStartElement("url");
                    writer.WriteElementString("loc", YafBuildLink.GetLinkNotEscaped(ForumPages.topics, 
true, "f={0}", drow["ForumID"] ));
                    writer.WriteElementString("lastmod",
                                              DateTime.Now.ToString("yyy-MM-dd",
                                                                    System.Globalization.CultureInfo.InvariantCulture));
                    writer.WriteElementString("changefreq", ChangeFrequency.always.ToString());
                    writer.WriteElementString("priority", "0.8");
                    writer.WriteEndElement(); // url
                }

                writer.WriteEndElement(); // urlset 
              
            }
            context.Response.ContentType = "text/xml";
        }

        #endregion
    }
}



2. web.config

<system.webServer>
....
<handlers>
<add name="SitemapHandler" verb="*" path="sitemap.axd" type="YAF.SitemapHandler, YAF" />

3. In robots.txt

Sitemap: http://forum.yetanotherforum.net//sitemap.axd 

Of cause it should be customized and the working example is just to show a general approach in YAF.
guest
2012-10-03T14:04:20Z
Thanks for your quick reply.

Now I am able to create sitemap, but if the url has some special characters like %,?,.,#......

In Yetanotherfoum software, by which method we can make actual url by escaping these characters.
dcb1101
2012-10-31T14:18:54Z
Thank you for the code example, however I am getting the error:
'YAF.Core.YafContext' does not contain a definition for 'PageModuleID' and no extension method 'PageModuleID' accepting a first argument of type 'YAF.Core.YafContext' could be found (are you missing a using directive or an assembly reference?) C:\Sites\rs\forum\Classes\SitemapHandler.cs 57 71

I'm using YAF 1.9.6

bbobb
  •  bbobb
  • 100% (Exalted)
  • YAF Developer
2012-10-31T16:48:04Z
This is my custom code, look at the fixed code. Keep in mind that any customization is your problem.
dcb1101
2012-11-02T00:01:46Z
Thank you. Now using the code as you edited and without customizing it, I am getting the error message:
Exception information:
Exception type: System.TypeLoadException
Exception message: Could not load type 'YAF.SitemapHandler' from assembly 'YAF'.

Thank you for your help

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved