Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to remove menu items as per roles in asp.net
    primarykey
    data
    text
    <p>I have </p> <p>Web.sitemap like this :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" &gt; &lt;siteMapNode url="" title="" description=""&gt; &lt;siteMapNode url="~/Home.aspx" title="Home" description=" this is the home page" /&gt; &lt;siteMapNode url="~/ProjectList.aspx" title="Project List" description="Approved projects" /&gt; &lt;siteMapNode url="" title="Project Choices" description=""&gt; &lt;siteMapNode url="~/StudentChoices.aspx" title="Student Project Choices" description="" /&gt; &lt;siteMapNode url="~/StaffChoices.aspx" title="Supervisor Project Choices" description="" /&gt; &lt;/siteMapNode&gt; &lt;siteMapNode url="~/AllocationList.aspx" title="Project Allocation List" description="" /&gt; &lt;siteMapNode url="" title="Submit Proposal" description="" &gt; &lt;siteMapNode url="~/submit.aspx" title="New Proposal" description="new proposal" /&gt; &lt;siteMapNode url="~/reSubmit.aspx" title="Re-Submit Proposal" description="re submit proposal"/&gt; &lt;/siteMapNode&gt; &lt;siteMapNode url="~/StaffRecords.aspx" title="Staff Records" description="" &gt; &lt;siteMapNode url="~/addStaff.aspx" title="Add new Staff" description="" /&gt; &lt;/siteMapNode&gt; &lt;siteMapNode url="~/StudentRecords.aspx" title="Student Records" description="" /&gt; &lt;siteMapNode url="~/Administration.aspx" title="Administration" description="" /&gt; &lt;/siteMapNode&gt; &lt;/siteMap&gt; </code></pre> <p>I used this sitemap for creating menu items : like following :</p> <pre><code>&lt;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"&gt; &lt;DynamicHoverStyle BackColor="#9999FF" ForeColor="Black" /&gt; &lt;DynamicMenuItemStyle BackColor="#0099FF" ForeColor="Black" /&gt; &lt;DynamicMenuStyle BackColor="#0099FF" /&gt; &lt;DynamicSelectedStyle BackColor="#0099FF" ForeColor="Black" /&gt; &lt;/asp:Menu&gt; &lt;asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /&gt; </code></pre> <p>on code be-hide i wrote following things :</p> <pre><code>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); } } } </code></pre> <p>and web config like this</p> <pre><code>&lt;appSettings&gt; &lt;add key="AdminRole" value="Admin"/&gt; &lt;add key="StaffRole" value="Staff"/&gt; &lt;add key="StudentRole" value="Student"/&gt; &lt;/appSettings&gt; </code></pre> <p>but I am still able to see those menus, I am not able find out why it's not removing, Can anyone tell me why? Show me sample code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload