Search code examples
asp.net-mvcmvcsitemapprovider

MvcSiteMapProvider - Prevent display/serving sitemap.xml


I have a web app that uses MvcSiteMapProvider, but I don't want it to server /sitemap.xml as every page but the login page requires authentication, so there is no need for the public to see my sitemap.

Is there a way to turn off the the /sitemap.xml file in config? Or a way to do it with RoutesConfig?


Solution

  • As per the documentation, if using internal DI, you can disable the /sitemap.xml endpoint using the MvcSiteMapProvider_EnableSitemapsXml setting.

    <appSettings>
        <add key="MvcSiteMapProvider_EnableSitemapsXml" value="false"/>
    </appSettings>
    

    If using external DI, you need to remove this line from the /App_Start/MvcSiteMapProviderConfig.cs file (or anywhere else it may exist in your application startup code).

    // Register the Sitemaps routes for search engines
    //XmlSiteMapController.RegisterRoutes(RouteTable.Routes);
    

    FYI - although this setting does what you asked, there really was no problem to begin with. Search engines do not scan web sites for XML sitemap files, they have to be explicitly submitted. According to the sitemap protocol, they can be submitted via HTTP request, via search engine control panel, or by adding the location to the \robots.txt file. But none of these are done without explicit intervention on the part of the webmaster. In all cases, the webmaster chooses the URL that the XML sitemap will be hosted at. Unlike the \robots.txt file, there is no default location for it. We chose the most reasonable logical path \sitemap.xml, but technically it could be anything.