我有
Web.sitemap 像这样:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="~/Home.aspx" title="Home" description=" this is the home page" />
<siteMapNode url="~/ProjectList.aspx" title="Project List" description="Approved projects" />
<siteMapNode url="" title="Project Choices" description="">
<siteMapNode url="~/StudentChoices.aspx" title="Student Project Choices" description="" />
<siteMapNode url="~/StaffChoices.aspx" title="Supervisor Project Choices" description="" />
</siteMapNode>
<siteMapNode url="~/AllocationList.aspx" title="Project Allocation List" description="" />
<siteMapNode url="" title="Submit Proposal" description="" >
<siteMapNode url="~/submit.aspx" title="New Proposal" description="new proposal" />
<siteMapNode url="~/reSubmit.aspx" title="Re-Submit Proposal" description="re submit proposal"/>
</siteMapNode>
<siteMapNode url="~/StaffRecords.aspx" title="Staff Records" description="" >
<siteMapNode url="~/addStaff.aspx" title="Add new Staff" description="" />
</siteMapNode>
<siteMapNode url="~/StudentRecords.aspx" title="Student Records" description="" />
<siteMapNode url="~/Administration.aspx" title="Administration" description="" />
</siteMapNode>
</siteMap>
我使用此站点地图创建菜单项:如下所示:
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"
BackColor="#33CCFF" Font-Overline="False" DataSourceID="SiteMapDataSource1"
Font-Size="Larger" ForeColor="Black" ItemWrap="True" StaticDisplayLevels="2"
StaticSubMenuIndent="60px" Width="100%" OnMenuItemDataBound="Menu1_MenuItemDataBound">
<DynamicHoverStyle BackColor="#9999FF" ForeColor="Black" />
<DynamicMenuItemStyle BackColor="#0099FF" ForeColor="Black" />
<DynamicMenuStyle BackColor="#0099FF" />
<DynamicSelectedStyle BackColor="#0099FF" ForeColor="Black" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
在隐藏代码上,我写了以下内容:
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
//string role = Session["Roles"].ToString();
string AdminRole = ConfigurationManager.AppSettings["AdminRole"];
string StaffRole = ConfigurationManager.AppSettings["StaffRole"];
string StudentRole = ConfigurationManager.AppSettings["StudentRole"];
if (StaffRole == "Staff")
{
if (e.Item.Text == "Project Choices" ||
e.Item.Text == "Staff Records" ||
e.Item.Text == "Student Records")
{
Menu1.Items.Remove(e.Item);
}
}
}
和这样的网络配置
<appSettings>
<add key="AdminRole" value="Admin"/>
<add key="StaffRole" value="Staff"/>
<add key="StudentRole" value="Student"/>
</appSettings>
但我仍然能够看到这些菜单,我无法找出为什么它没有被删除,谁能告诉我为什么?给我看示例代码。