Is it possible to create a sitemap.xml file which is dynamic and is actually created each time it is requested using c#
The开发者_运维百科 obvious thing to do would be to call the file sitemap.aspx and have it return XML, but it has to be called sitemap.xml and look like an XML file (headers etc) to the requester.
Try creating a generic handler, sitemap.ashx file that returns the XML. Then rename it to sitemap.xml. Make sure you set the content type to xml:
context.Response.ContentType = "text/xml";
Then in IIS, you would have to map the xml file extension to the ASP.NET engine.
I'm not 100% sure it'll work since it's a .xml extension, but it's worth trying if you really want to show the .xml extension to the user.
精彩评论