如果前台有一个web.sitemap文件,后台也有一个admin.sitemap文件.把菜单项写入到.sitemap这两个文件中.
前台有一个母板页Default.master,后来也有一个母板页admin.master.
Default.master:
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"
Orientation="Horizontal"
MaximumDynamicDisplayLevels="5" StaticEnableDefaultPopOutImage="False"
CssClass="Menu"
DisappearAfter="200" StaticDisplayLevels="2" DynamicVerticalOffset="2"
StaticSubMenuIndent="6px"
DynamicEnableDefaultPopOutImage="False">
<StaticMenuItemStyle CssClass="Menu" />
<DynamicMenuItemStyle CssClass="SubMenu" />
</asp:Menu>
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
SiteMapPath不需要指明SiteMapProvider,默认就是web.sitemap
SiteMapDataSource1 默认的SiteMapProvider是web.可以才代码判断.给SiteMapProvider赋值.比如权限的
控制,不同人看到的菜单一样.
admin.master.
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1"
Orientation="Horizontal"
MaximumDynamicDisplayLevels="5" StaticEnableDefaultPopOutImage="False"
CssClass="Menu"
DisappearAfter="200" StaticDisplayLevels="2" DynamicVerticalOffset="2"
StaticSubMenuIndent="6px"
DynamicEnableDefaultPopOutImage="False">
<StaticMenuItemStyle CssClass="Menu" />
<DynamicMenuItemStyle CssClass="SubMenu" />
</asp:Menu>
<asp:SiteMapPath ID="SiteMapPath1" runat="server" SiteMapProvider="admin">
</asp:SiteMapPath>
SiteMapPath要指明SiteMapProvider="admin",不然默认是web.sitemap
c#:
protected void Page_Load(object sender, EventArgs e)
{
GetMenuControl();
}
public void GetMenuControl()
{
SiteMapDataSource1.SiteMapProvider = "admin";
}
/*web.config配置如下
<siteMap>
<providers>
<add name="web" type="System.Web.XmlSiteMapProvider"
siteMapFile="Web.sitemap"/>
<add name="Admin" type="System.Web.XmlSiteMapProvider"
siteMapFile="~/SiteMap/Admin.sitemap"/>
</providers>
</siteMap>
*/