SiteMap.Provider 属性
定义
获取当前站点地图的默认 SiteMapProvider 对象。Gets the default SiteMapProvider object for the current site map.
public:
static property System::Web::SiteMapProvider ^ Provider { System::Web::SiteMapProvider ^ get(); };
public static System.Web.SiteMapProvider Provider { get; }
member this.Provider : System.Web.SiteMapProvider
Public Shared ReadOnly Property Provider As SiteMapProvider
属性值
SiteMap 的默认站点地图提供程序。The default site map provider for the SiteMap.
例外
未启用站点地图功能。The site map feature is not enabled.
配置中指定的默认提供程序不存在。The default provider specified in the configuration does not exist.
只有在低信任或以上设置的情况下运行时,才支持此功能。The feature is supported only when running in Low trust or higher.
示例
下面的代码示例演示如何 SiteMapProvider 使用静态属性访问站点的默认对象 Provider 。The following code example demonstrates how to access the default SiteMapProvider object for the site by using the static Provider property.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// Navigate the SiteMap built by the default SiteMapProvider.
Response.Write(SiteMap.RootNode.ToString() + "<BR>");
Response.Write(SiteMap.RootNode.Url + "<BR>");
Response.Write(SiteMap.RootNode.Title + "<BR>");
foreach (SiteMapNode sitemapnode in SiteMap.RootNode.ChildNodes)
{
// Iterate through the ChildNodes SiteMapNodesCollection
// maintained by the RootNode.
Response.Write(sitemapnode.Url + "<BR>" );
}
IEnumerator providers = SiteMap.Providers.GetEnumerator();
while (providers.MoveNext())
{
Response.Write(providers.Current);
Response.Write(" ");
Response.Write("<BR>");
}
}
</SCRIPT>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat="server">
Private Sub Page_Load(Sender As Object, E As EventArgs)
' Navigate the SiteMap built by the default SiteMapProvider.
Response.Write(SiteMap.RootNode.ToString() & "<BR>")
Response.Write(SiteMap.RootNode.Url & "<BR>")
Response.Write(SiteMap.RootNode.Title & "<BR>")
Dim sitemapnode As SiteMapNode
For Each sitemapnode In SiteMap.RootNode.ChildNodes
' Iterate through the ChildNodes SiteMapNodesCollection
' maintained by the RootNode.
Response.Write(sitemapnode.Url & "<BR>" )
Next
Dim providers As IDictionaryEnumerator = SiteMap.Providers.GetEnumerator()
While (providers.MoveNext())
Response.Write(providers.Current)
Response.Write(" ")
Response.Write("<BR>")
End While
End Sub ' Page_Load
</SCRIPT>
注解
默认情况下,将 XmlSiteMapProvider 使用对象,并从位于站点根目录中的 web.config 文件加载站点导航数据。By default, the XmlSiteMapProvider object is used and site navigation data is loaded from the Web.sitemap file that is located in the root directory of the site. 管理类中标识了此项,管理类用于管理站点导航配置和 Web.config 文件的 "站点地图配置" 部分。This is identified in the management classes that manage the site navigation configuration and the site map configuration section of the Web.config files. 默认情况下,它是类的实例 XmlSiteMapProvider ,该类使用 web.config 文件作为其持久性存储区。By default, it is an instance of the XmlSiteMapProvider class, which uses the Web.sitemap file as its persistent store. 但是,您可以通过编写实现抽象类的类来实现自己的站点地图存储和配置方案 SiteMapProvider 。However, you can implement your own site map storage and configuration scheme by writing a class that implements the abstract SiteMapProvider class. 有关编写您自己的提供程序的详细信息,请参阅 SiteMapProvider 。For more information on writing your own provider, see SiteMapProvider.