Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sitemap.xml url returns 404 Error

I have a large affiliate marketing site with millions of products hosted on Windows Azure. For SEO I have to provide a sitemap.xml which is dynamically created.

  public ActionResult SiteMap()
    {
        string sitemapUrl = "https://trendley.blob.core.windows.net/sitemap/sitemap.xml";

        byte[] bImage = null;
        using (WebClient wc = new WebClient())
        {
            bImage = wc.DownloadData(sitemapUrl);
        }
        return File(bImage, "application/octet-stream");
    }

I added the follwoing route to my RouteConfig:

   routes.MapRoute("Sitemap",
"sitemap.xml",
new { controller = "Home", action = "Sitemap" });

Unfortunately this is not workting. I get -> HTTP Error 404.0 - Not Found

When I change "sitemap.xml" to sitemapxml (remove the extension) my controller method is invoked. Already did some research and played with my web.config but nothing seems to work.

First thing I tried was to add:

<modules runAllManagedModulesForAllRequests="true" />

Second thing:

 <add
name="AdfsMetadata"
path="sitemap.xml"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />

Can someone tell me how to acomplish this. Do I have to write my own Handler for this?

Cheers, Stefan

like image 454
stefan Avatar asked Feb 03 '26 07:02

stefan


1 Answers

The reason that that route is not working is because by default .xml is handled by the "StaticFileHandler" in IIS so when the request comes in ASP.net is not invoked.

Option 1: Enable runAllManagedModulesForAllRequests - in your web .config add the following

<modules runAllManagedModulesForAllRequests="true" />

It goes inside of the system.webserver node.

option 2: Add a mapping for .xml to IIS and force that file extension into the ASP.net pipeline. See here

like image 117
iamkrillin Avatar answered Feb 05 '26 07:02

iamkrillin