Creating runtime menus based on user role

I am trying to create a menu that sorted differently depending on the role of the user.

For example, if the user is an administrator, the following menu is displayed:

  • Adminpan

  • Registeruser

  • UserRoles

and if the user is the main role:

  • ViewProducts

  • makeOrder

This is an example layout.

I would appreciate help as I searched the net for 2 hours with no luck.

Thank.

+5
source share
2 answers

What you want to do is that in your web.config there is a section in the section system.web, for example:

    <siteMap>
        <providers>
            <add name="anonymous" type="System.Web.XmlSiteMapProvider" siteMapFile="~/YourAnonymouse.sitemap"/>
            <add name="user" type="System.Web.XmlSiteMapProvider" siteMapFile="~/YourNormalUser.sitemap"/>
            <add name="admin" type="System.Web.XmlSiteMapProvider" siteMapFile="~/YourAdmin.sitemap"/>
        </providers>
    </siteMap>

, sitemap , .

SiteMapDataSource, . , . Page_Load() Sitemap SiteMapDataSource:

    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        if (HttpContext.Current.User.IsInRole("Admin"))
            SiteMapDataSource1.Provider = SiteMap.Providers("admin");
        else
            SiteMapDataSource1.Provider = SiteMap.Providers("user");
    }
    else
        SiteMapDataSource1.Provider = SiteMap.Providers("anonymous");
+4

, MasterPages, Postback Initial Page , - ActiveDirectory .

0

All Articles