public class MySitemapProvider : XmlSiteMapProvider
{
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
if (node.Roles != null&&node.Roles.Count==0)
return true;
foreach (string role in node.Roles)
{
if (role == "*")
return true;
if (Roles.IsUserInRole(role))
{
return true;
}
}
return false;
}
}
{
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
if (node.Roles != null&&node.Roles.Count==0)
return true;
foreach (string role in node.Roles)
{
if (role == "*")
return true;
if (Roles.IsUserInRole(role))
{
return true;
}
}
return false;
}
}
在webconfig中添加:
<system.web>
<siteMap defaultProvider="MySitemapProvider" enabled="true">
<providers>
<add name="MySitemapProvider"
description="Default SiteMap provider."
type="WebApplication2.MySitemapProvider"
siteMapFile="Web.sitemap"
securityTrimmingEnabled="true" />
</providers>
</siteMap>
</system.web>