views:

633

answers:

2

I am so frustrated.

I have godaddy and I built a Sitemap class to use for my site drinkingfor.com.

But the httphandler doesn't seem to be picked up under GoDaddy servers. Need some help.

The code works on my Dev machine, but once I move it over to Godaddy it shows up as NOT Found. I swear this is like my last straw with Godaddy.

The sitemap file should show up at http://www.drinkingfor.com/sitemap.axd, but as you can see the page is not found. Any help is appreciated.

My Web.Config for httphandlers is:

<add verb="*" path="sitemap.axd" type="HttpExtensions.SitemapHandler"/>

And my Sitemap Class is:

public class Sitemap : IHttpHandler
{
    /// <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; }
}

public void ProcessRequest(HttpContext context)
{

    context.Response.ContentType = "text/xml";
    using (TextWriter textWriter = new StreamWriter(context.Response.OutputStream, System.Text.Encoding.UTF8))
    {
        XmlTextWriter writer = new XmlTextWriter(textWriter);
        writer.Formatting = Formatting.Indented;
        writer.WriteStartDocument();
        writer.WriteStartElement("urlset");
        writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");
        writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");

        SupportFramework.GlobalDataContext db = new SupportFramework.GlobalDataContext();
        var getItem = (from glob in db.Global_Sitemaps
                       select glob);

        foreach (var item in getItem)
        {
            writer.WriteStartElement("url");
            writer.WriteElementString("loc", item.url);
            writer.WriteElementString("changefreq", item.changefreq);
            writer.WriteElementString("lastmod", item.lastmod.ToString("yyyy-MM-dd");
            writer.WriteEndElement(); // url
        }
        writer.WriteEndElement(); // urlset
    }
}
}
public class SiteMap
{
public SiteMap()
{ }

private enum ChangeFreq
{
    always,
    hourly,
    daily,
    weekly,
    monthly,
    yearly,
    never
}

/// <summary>
/// Adds a Node to the Site Map
/// </summary>
/// <param name="url">URL to add to SiteMap</param>
/// <param name="modified">true oo false if the item has just been modified.</param>
public static void AddNode(string url, bool modified)
{
    SupportFramework.GlobalDataContext db = new SupportFramework.GlobalDataContext();
    var getItem = (from glob in db.Global_Sitemaps
                   where glob.url == url
                   select glob).FirstOrDefault();

    if (getItem == null)
    {
        SupportFramework.Global_Sitemap globs = new SupportFramework.Global_Sitemap();
        globs.url = url;
        globs.lastmod = DateTime.UtcNow;
        globs.changefreq = ChangeFreq.monthly.ToString();
        db.Global_Sitemaps.InsertOnSubmit(globs);
        db.SubmitChanges();
    }
    else
    {
        switch (modified)
        {
            case true:
                getItem.lastmod = DateTime.UtcNow;

                TimeSpan span = DateTime.UtcNow.Subtract(getItem.lastmod);
                if (span.Days > 365)
                    getItem.changefreq = ChangeFreq.yearly.ToString();
                else if (span.Days > 31)
                    getItem.changefreq = ChangeFreq.monthly.ToString();
                else if (span.Days > 7)
                    getItem.changefreq = ChangeFreq.weekly.ToString();
                else if (span.Hours > 24)
                    getItem.changefreq = ChangeFreq.daily.ToString();
                else
                    getItem.changefreq = ChangeFreq.hourly.ToString();
                db.SubmitChanges();
                break;
        }
    }
}
    }
+2  A: 

GoDaddy probably doesn't have *.axd mapped in their IIS configuration for shared servers.

There isn't much you can do about that, but have you considered simply using a .ASHX http handler? They are designed for exactly this reason, when you can't configure IIS.

To use it, simply create a new .ASHX in visual studio and paste your code in it. Browsing to that file will run your handler.

I use them all the time.

FlySwat
Thank you. This worked.
Scott
A: 

I will try it, thank you.

But your assumption isn't right about GoDaddy not having axd's mapped. Since I also have BlogEngine.Net and it uses a SLEW of httphandlers so my problem just doesn't make sense.

Any other person want to give it a go?

Scott