Access to the path ... is denied

My CMS writes a sitemap xml file, for google analytics, to the server whenever I create or update a page. The error is:

Access to the path 'D:\\home\\ensample\\mrweinerschnitzelandpie.com\\sitemap.xml' is denied.

I imagine that happens because IUSR_machineName doesn’t have proper permissions. I have no issues on my development server (which is pretty much default) but to avoid this in the future, instead of having a method that writes an XML file can I just output an XML filestream? I can barely remember the reasons I used the file writing at all (caching and file dependencies maybe) and that’s all been replaced.

Am I on the right path by thinking filestream is the answer or can I just write an aspx page that outputs the sitemap.xml file? Am I wrong in imagining there is a difference between the two?

Here is what I did using the existing sitemap writer (siteMap.writeSitemap):

    public class sitemapController : Controller
    {
		private ISiteMap siteMap;
		public sitemapController(ISiteMap siteMap)
		{
			this.siteMap = siteMap;
		}
        public XDocument Index()
        {
			Response.ClearHeaders();
			Response.AddHeader("Content-Type", "text/xml");
            return siteMap.writeSitemap();
        }

    }

Seems to work

As stated above it is directory permissions. Setting the ouput stream to xml will work fine, but its better for SEO to have an actual .xml extension as that is what all search engines look for.

What I did is create an IHttpHandler that outputs what I want and routed all sitemap.xml requests to said handler

I’m nor familiar. I’ll have to look that up. If I put [highlight=robots.txt]Sitemap: http: //example.com/sitemap
(without the space between : and / )

 in my robots.txt will that handle the situation?

Oh, wait. I’ll just do this: [HIGHLIGHT=Global.asax]routes.MapRoute(“sitemap”, “sitemap.xml”, new { controller = “Sitemap”, action = “Index” });

 That should have been my first thought. 

Thanks for the idea. :)