Reputation: 85
I am trying to create a menu that sorts differently depending on what the user role is.
For example, if the user is an Admin role, the menu shown will be:
AdminPane
RegisterUser
UserRoles
and if the user is Basic role:
ViewProducts
makeOrder
This is a layout example.
I would appreciate some help as I've been searching the net for 2 hours with no luck.
Thanks.
Upvotes: 5
Views: 1501
Reputation:
What you want to do is in your web.config have a section in your system.web
section, like so:
<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>
Then with this, you'll have three site map providers defined, each pointing to their respective sitemap
files for the necessary menu you are looking for for each user type.
Then you'll have a SiteMapDataSource
that your menu server control will use. This will most likely exist on your master page. On your Page_Load()
of your master page you'll have logic to dynamically and programmatically set the sitemap data source of your SiteMapDataSource
control:
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");
Upvotes: 4
Reputation: 18863
All of this can be accomplished by using MasterPages and on Postback or Initial Page load you can create a Session Variable that stores the values or write something against ActiveDirectory fairly simple..
Upvotes: 0