This is a migrated thread and some comments may be shown as answers.

Using RadMenu with Membership Provider

6 Answers 277 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 15 Feb 2008, 06:59 PM
I am developing an ASP.NET app using C# 3.5, VS 2008.  I am using the AspNetSqlMembershipProvider with three levels of users, the general public who do not login, users and administrators.  There are some features that only administrators can access and some features that only users and administrators can access.

Currently, I am using a WebSiteMap, SiteMapDataSource and TreeView to handle the navigation.  When first accessing the app, the restricted features are not visiable.  When an user logs in, then the user features become visiable on the tree view.  Likewise, when an administrator logs in, then both the user and administrator features appear.

I would like to replace the WebSiteMap, SiteMapDataSource and TreeView with the Prometheus RadMenu with the options being displaced horizonally across the top of the MasterPage. 

I did try the option of indicating that the data source to the RadMenu was the SiteMapDataSource but this option only displayed the first note ("Home") with the other options as children and only when the home option was selected.  (The first leve in a WebSiteMap can have only one note.)

Does anyone know how to integrate the RadMenu with the MembershipProvider such that retricted buttons only appear if the user is authorized to access those features>

6 Answers, 1 is accepted

Sort by
0
Philip
Top achievements
Rank 1
answered on 17 Feb 2008, 08:34 PM
The solution I used was to use an XML file for the menu source and define the source in the codebehind based on the user's group membership. There are different XML files for each group defining which links they can see.

<telerik:RadMenu ID="RadMenu1" EnableEmbeddedSkins="false" Skin="scSkin" runat="server" /> 


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 
        If Not Page.IsPostBack Then  
            If Roles.IsUserInRole("Administrator") Then  
                RadMenu1.LoadContentFile("~/App_Data/scMenuData_admin.xml")  
            ElseIf Roles.IsUserInRole("User") Then  
                RadMenu1.LoadContentFile("~/App_Data/scMenuData_user.xml")  
            End If  
        End If  
    End Sub 

Hope that helps you out.
0
Robert
Top achievements
Rank 1
answered on 18 Feb 2008, 10:18 PM
Phillip:

Is your code running in the master page code behind or on the various content pages code behind?
0
Philip
Top achievements
Rank 1
answered on 18 Feb 2008, 11:07 PM
My menu is defined on the master page and the coding that loads the XML file is on the code-behind for the master page.
0
Robert
Top achievements
Rank 1
answered on 18 Feb 2008, 11:48 PM
Phillip:

I tried doing that but the RadMenu is not visible to the master page code behind:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

namespace ElectronicLane

{
public partial class MasterPage : System.Web.UI.MasterPage
{
     protected void Page_Load(object sender, EventArgs e)
     {
 if (!Page.IsPostBack)
 { 
      if (Roles.IsUserInRole("User") || Roles.IsUserInRole("Admin"))
      {
  RadMenuItem RootItem = new RadMenuItem();
  RootItem.Text = "New Root Item";
  RadMenu1.Items.Add(RootItem);  <== Can't find RadMenu1
      }
 }
}

On the MasterPage.master, I have:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"  Inherits="MasterPage" %>

and 

<telerik:RadMenu ID="RadMenu1" Runat="server" Flow="Horizontal" Skin="Inox">
 <DefaultGroupSettings Flow="Vertical" ExpandDirection="Auto"></DefaultGroupSettings>
 <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
 <Items>....</Items>
 <ExpandAnimation Type="OutQuart"></ExpandAnimation>
</telerik:RadMenu>

0
Philip
Top achievements
Rank 1
answered on 18 Feb 2008, 11:53 PM
Are you registering the control on the MasterPage.master as well?

You need to have this line underneath your <%@ Master... line

<%@ Register Assembly="Telerik.Web.UI" NameSpace="Telerik.Web.UI" TagPrefix="telerik" %> 
0
Robert
Top achievements
Rank 1
answered on 19 Feb 2008, 04:36 PM
This is the entire MasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"
    Inherits="MasterPage" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ElectronicLane</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td align="right" colspan="2">
                    <asp:LoginName ID="loginName1" runat="server" FormatString="Welcome {0} to our site."
                        Font-Italic="True" ForeColor="#3333FF" />
                    &nbsp
                    <asp:LoginStatus ID="LoginStatus1" runat="server" Font-Italic="True" LoginText="Authorized Dealer Login"
                        LogoutPageUrl="~/Default.aspx" />
                </td>
            </tr>
            <tr>
                <td class="firstColumn">
                    &nbsp<img alt="" src="Images/ElectronicLane.gif" />
                </td>
                <td align="center" class="secondColumn">
                    <table id="Table1" runat="server">
                        <tr>
                            <td>
                                <asp:Label ID="Label2" runat="server" Text="2709 Electronic Lane, Dallas, TX 75220"
                                    Font-Bold="True" Font-Italic="True" ForeColor="Black" Height="20px" Width="387px"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label ID="Label3" runat="server" Text="Phone: 214-956-0555 FAX: 1-800-932-2960"
                                    Font-Bold="True" Font-Italic="True" ForeColor="Black" Height="20px" Width="387px"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <table width="100%">
                        <tr>
                            <td>
                                <telerik:RadMenu ID="RadMenu1" Runat="server" Flow="Horizontal" Skin="Inox">
<DefaultGroupSettings Flow="Vertical" ExpandDirection="Auto"></DefaultGroupSettings>

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

                                    <Items>
                                        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide"
                                            NavigateUrl="Default.aspx" Text="Home">
                                            <groupsettings expanddirection="Auto" flow="Vertical" />
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide"
                                            NavigateUrl="Products.aspx" Text="Products">
                                            <groupsettings expanddirection="Auto" flow="Vertical" />
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide"
                                            NavigateUrl="NewsandEvents.aspx" Text="News and Events">
                                            <groupsettings expanddirection="Auto" flow="Vertical" />
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide"
                                            NavigateUrl="AboutUs.aspx" Text="AboutUs">
                                            <groupsettings expanddirection="Auto" flow="Vertical" />
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem runat="server" ExpandMode="ClientSide"
                                            NavigateUrl="NewDealer.aspx" Text="New Dealer">
                                            <groupsettings expanddirection="Auto" flow="Vertical" />
                                        </telerik:RadMenuItem>
                                    </Items>

<ExpandAnimation Type="OutQuart"></ExpandAnimation>
                                </telerik:RadMenu>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td>
                                <img alt="" src="Images/Edge.gif" /></td>
                        </tr>
                        <tr>
                            <td>
                                <img alt="" src="Images/Cedia.gif" /></td>
                        </tr>
                    </table>
                </td>
                <td class="secondColumn" style="vertical-align: top; border-top: olive thick solid;
                    border-left: olive thick solid; border-top-width: thick; border-left-width: thick;
                    border-left-color: olive; border-top-color: olive; border-right-width: thick;
                    border-right-color: olive;">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Tags
Menu
Asked by
Robert
Top achievements
Rank 1
Answers by
Philip
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or