MvcSiteMapProvider-阻止显示/提供sitemap.xml [英] MvcSiteMapProvider - Prevent display/serving sitemap.xml

查看:89
本文介绍了MvcSiteMapProvider-阻止显示/提供sitemap.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MvcSiteMapProvider的Web应用程序,但是我不希望每个页面都将它存储在/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.

是否可以关闭config中的/sitemap.xml文件?还是使用RoutesConfig做到这一点的方法?

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

推荐答案

按照文档,如果使用内部DI,则可以使用 MvcSiteMapProvider_EnableSitemapsXml 设置禁用/sitemap.xml 端点.>

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>

如果使用外部DI,则需要从/App_Start/MvcSiteMapProviderConfig.cs 文件(或应用程序启动代码中可能存在的任何其他位置)中删除此行.

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);

仅供参考-尽管此设置可以满足您的要求,但一开始确实没有问题.搜索引擎不会在网站上扫描XML站点地图文件,必须明确提交它们.根据站点地图协议,可以通过HTTP请求通过搜索引擎控制面板提交它们,或将位置添加到 \ robots.txt 文件中.但是,如果没有网站管理员的明确干预,上述任何一项都无法完成.在所有情况下,网站管理员都将选择XML网站地图的托管​​网址.与 \ robots.txt 文件不同,该文件没有默认位置.我们选择了最合理的逻辑路径 \ sitemap.xml ,但是从技术上讲,它可以是任何东西.

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.

这篇关于MvcSiteMapProvider-阻止显示/提供sitemap.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆