Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hii..

I am stuck in one scenario where there are multiple master pages. Here's my question :-

My Website uses Asp.Net default membership provider. I have 3 users and 3 roles.

I have a page called as "RaiseTicket.aspx" this page is accessed by users of all roles. The design of master pages is 2 column layout. Left its the navigation and right is the main content area. All roles have different links on left column. Admin have all links, the other 2 roles have limited links. What I want is the links on the admin page should be visible if admin navigates to any of the page. And if the user navigates to RaiseTicket.aspx page he should be only visible his own links.

Its like 1 page having multiple views of master pages. How should I achieve that. or if you have different view please tell me.
Posted

u can follow the below link ...


[^]


on the navigation panel give runat="server" attribute and on content page find control by master page and then you can access the control and can hide it.
 
Share this answer
 
You could do this by implementing you own a site map provide class (that extend StaticSiteMapProvider) and based on the user roles to add or not links nodes to you master page. The building of your master page links node based on the user roles have to be done by overriding the method BuildSiteMap like in the next example:

C#
/// <summary>
        /// Initializes a new instance of the System.Web.SiteMapNode class using the
        /// specified site map provider that manages the node, URL, title, description,
        /// _userRoles, additional attributes, and explicit and implicit resource keys for
        /// localization.
        /// </summary>
        /// <param name="key">A provider-specific lookup key.</param>
        /// <param name="title">A label for the node, often displayed by navigation controls.</param>
        /// <param name="url">The URL of the page that the node represents within the site.</param>
        /// <param name="description">The node description.</param>
        /// <param name="_userRoles">An System.Collections.IList of _userRoles that are allowed to view the page.</param>
        /// <returns>The new created site map node.</returns>
        private SiteMapNode CreateNode(string key, string title, string url, string description, IList _userRoles)
        {
            return new SiteMapNode(this, key, url, title, description, _userRoles, null, null, null);
        }

        /// <summary>
        /// Add a new site map node node.
        /// </summary>
        /// <param name="node">The site map node.</param>
        /// <param name="parentNode">The parent node.</param>
        protected override void AddNode(SiteMapNode node, SiteMapNode parentNode)
        {
            base.AddNode(node, parentNode);
            _rebuildSiteMap = true;
        }

        /// <summary>
        /// Remove a node from the site map.
        /// </summary>
        /// <param name="node">The node to remove.</param>
        protected override void RemoveNode(SiteMapNode node)
        {
            base.RemoveNode(node);
            _rebuildSiteMap = true;
        }

        /// <summary>
        /// Gets the root node.
        /// </summary>
        /// <returns>The root node.</returns>
        protected override SiteMapNode GetRootNodeCore()
        {
            return BuildSiteMap();
        }

        /// <summary>
        /// Retrieves a Boolean value indicating whether the specified site map node
        /// can be viewed by the current user in the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="node">The site map node.</param>
        /// <returns>True if the node can be viewed by the user, otherwise false.</returns>
        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            return true;
        }

        /// <summary>
        /// The worker method that build the site map.
        /// </summary>
        /// <returns>The root node.</returns>
        public override SiteMapNode BuildSiteMap()
        {
            if (_rebuildSiteMap)
            {
                BuildMainSiteMap();
                //
                _rebuildSiteMap = false;
            }
            //
            return _rootNode;
        }

        /// <summary>
        /// Get the the root node for the current user.
        /// </summary>
        /// <returns>The root node or null.</returns>
        SiteMapNode GetRootNode()
        {
            if (_currentUser == null)
                return null;
            else if(_currentUser.UserRole == UserRoles.Administrator)
                return CreateNode("_root", Resources.Resource.MenuHome, "UserListPage.aspx?Role=2", null, _userRoles);
            else
                return CreateNode("_root", Resources.Resource.MenuHome, "ComplainListPage.aspx?Type=1", null, _userRoles);
        }

        /// <summary>
        /// The worker method that build the main site map.
        /// </summary>
        private void BuildMainSiteMap()
        {
            _rootNode = GetRootNode();
            if (_rootNode == null)
                return;
            //
            // Add the root node
            //
            base.AddNode(_rootNode, null);
            //
            SiteMapNode node, subNode;
            //
            // Complains, Chilreen, Cases
            //
            node = CreateNode("_complainNode",
                     Resources.Resource.MenuComplains, "ComplainListPage.aspx", null, _userRoles);
            base.AddNode(node, _rootNode);
            //
            node = CreateNode("_childrenNode",
                     Resources.Resource.MenuChildren, "ChildListPage.aspx", null, _userRoles);
            base.AddNode(node, _rootNode);
            //
            node = CreateNode("_casesNode",
                     Resources.Resource.MenuCases, "CaseListPage.aspx", null, _userRoles);
            base.AddNode(node, _rootNode);
            //
            // Protectors
            //
            if (_currentUser.UserRole == UserRoles.Administrator)
            {
                node = CreateNode("_protectorsNode",
                         Resources.Resource.MenuProtectors, null, null, _userRoles); //"ServiceListPage.aspx?Flag=0"
                base.AddNode(node, _rootNode);
                //
                subNode = CreateNode("_servicesNode",
                         Resources.Resource.MenuServices, "ServiceListPage.aspx", null, _userRoles);
                base.AddNode(subNode, node);
                //
                subNode = CreateNode("_centersNode",
                         Resources.Resource.MenuCenters, "CenterListPage.aspx", null, _userRoles);
                base.AddNode(subNode, node);
                //
                subNode = CreateNode("_ongNode",
                         Resources.Resource.MenuONGs, "ONGListPage.aspx", null, _userRoles);
                base.AddNode(subNode, node);
                //
                subNode = CreateNode("_familiesNode",
                         Resources.Resource.MenuFamilies, "FamilyListPage.aspx", null, _userRoles);
                base.AddNode(subNode, node);
            }
            else
            {
                node = CreateNode("_protectorsNode",
                         Resources.Resource.MenuFamilies, "FamilyListPage.aspx", null, _userRoles);
                base.AddNode(node, _rootNode);
            }
            //...
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900