• Hide Menu Items Based on User Role…


    You can hid menu items in ASP.NET based on the current user roll. To do this, you have to configure the web.sitemap and web.config files. This example assumes you have roles setup for your site/application. So, lets get started.

    In your web.sitemap file, add the roll=”RoleName” to the end of every “siteMapNode” that you want to restrict. Please note that if you do not want to restrict a page, set roll=”*”, to enable the page for all users.

    Once you have setup your web.sitemap file, proceed to configure your web.config file. You will need to add the following code to your web.config file.


    <siteMap enabled="true">
    <providers>
    <clear/>
    <add siteMapFile="Web.sitemap" name="AspNetXmlSiteMapProvider"
    type="System.Web.XmlSiteMapProvider" securityTrimmingEnabled="true"/>
    </providers>
    </siteMap>

    This will hide the menu item according to the user role. Congratulations, you now have a role driven menu system for your site/application.


    Be Sociable, Share!