一個例子如何推出自己的XmlSiteMapProvider與定製邏輯:
public class MyXmlSiteMapProvider : XmlSiteMapProvider
{
public override SiteMapNode FindSiteMapNode(string rawUrl)
{
SiteMapNode node = base.FindSiteMapNode(rawUrl);
if (node != null)
{
var page = HttpContext.Current.Handler as Page;
if (page != null)
{
page.Title = node.Title;
}
var newNode = node.Clone(true);
newNode.Url = rawUrl;
return newNode;
}
else
{
return null;
}
}
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
if (node.Roles.OfType<string>().Any(r => String.Equals(r, "*", StringComparison.Ordinal) || context.User.IsInRole(r)))
{
return true;
}
else
{
throw new InsufficientRightsException();
}
}
}
安裝到Web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">
<providers>
<clear />
<add name="MyXmlSiteMapProvider" type="MyXmlSiteMapProvider" siteMapFile="Web.sitemap" securityTrimmingEnabled="true" />
</providers>
</siteMap>
</system.web>
</configuration>
使用標準ASP.NET麪包屑控制:
<asp:SiteMapPath runat="server" RenderCurrentNodeAsLink="true" SkipLinkText="" />