More in this section

Forums / Developing with Sitefinity / Custom Navigation based on authentication

Custom Navigation based on authentication

9 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    06 Jan 2010
    Link to this post
    Help!  We are building a site that has a top level navigation tab called Membership. For a public user, the Mebership landing page delivers information on how to join, and its sub-page navigation will deliver information/pages based on a non-member role.
    If the user logs in (login is actaully done through a third party with credentials and tokens being passed back and forth) we want the Membership landing page to deliver their member profile information instead and its sub-page navigation/pages will be based on the logged-in state and deliver the appropriate information.

    We have the Anonymous Access set to deny for the protected pages and if hit, they do successfully log the person in. My problem is how to then "hide' the public pages and 'show' the logged in pages?

    Right now we have the top level navigation as membership.aspx (public version) and membership_m.aspx (logged in version). If we simply use Sitefinity authentication to allow membership_m.aspx to show after log in there will be two Membership items im the navigation.

    I am curious to know how other have handled this (if anyone can understand this situation!)??

    Thank you
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jan 2010
    Link to this post
    Hi Laura,

    My problem is how to then "hide' the public pages and 'show' the logged in pages?

    You can get each item/node from your top navigation as CmsSiteMap node and cast it to CmsPage. Then you can check whether Anonymous access is true/ false for the item and show/hide it only in case the current request is authenticated/ not authenticated ( this.Page.Request.IsAuthenticated.)

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    06 Jan 2010
    Link to this post
    Hey Laura,

    Here is my idea.  (Tell me if it's crazy or not.)

    Instead of creating multiple membership pages, create 1 membership page.  The template the membership page uses can then have two PlaceHolders (authenticated & anonymous).  The code-behind for the master page (template) can be used to toggle the visibility of content based on the authenticated status.

    Check out this example

    ~/App_Master/Main2.master

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main2.master.cs" Inherits="App_Master_Main2" %> 
     
    <!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></title
        <asp:ContentPlaceHolder id="head" runat="server" /> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
            <asp:ContentPlaceHolder id="Authenticated" runat="server" /> 
            <asp:ContentPlaceHolder id="Anonymous" runat="server" /> 
        </div> 
        </form> 
    </body> 
    </html> 
     

    ~/App_Master/Main2.master.cs

    using System; 
     
    public partial class App_Master_Main2 : System.Web.UI.MasterPage 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (Request.QueryString["cmspagemode"] != "edit" && Request.QueryString["cmspagemode"] != "preview") 
            { 
                if (Request.IsAuthenticated == false) 
                { 
                    Authenticated.Visible = false
                    Anonymous.Visible = true
                } 
                else 
                { 
                    Authenticated.Visible = true
                    Anonymous.Visible = false
                } 
            } 
        } 

    This allows you to create authenticated & anonymous content for each Membership page.

    Please tell me your thoughts!

    Gabe Sumner - Evangelist
    Telerik | Sitefinity CMS
    http://www.sitefinitywatch.com/
  4. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    07 Jan 2010
    Link to this post
    Thanks Gabe!

    That was a thought I had in my head but didn't know how to exctly implement. That is much more logical. I will try it out and post the results.
    The logged in state does have some added pages but that can easily be controled through anonymous access in Sitefinity. But there are pages that are shown in the nav for non-logged in users for example:

    Sample Nav item if not logged in
    Membership

        Resources & Benefits 

        Our Program 

        Membership Categories 

        Group Enrollment Discount Program 

        Hear From IOur Members 

    Same Nav item when Logged in
    Membership

        Resources & Benefits 

        Career Resources 

        Scholarships  
        Volunteer Opportunities

  5. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    26 Jan 2010
    Link to this post
    Gabe - that solution works great. Thanks so much for the suggestion. In the end it became so simple. :)

    Now to implement based on Role and not just authentication.... have contentplaceholder (authenticated) and display for only roles1 and 2 but not for 3... somewhere I would need a list of roles with checkboxes for the user to select the appropriate role, then ....  i have to still figure this one out.

    Does anyone know how to (maybe in the database) change the name of a master page which in fact has 99% of the templates based off of it?

    Thank you,
    Laura
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    26 Jan 2010
    Link to this post
    Hello Laura,

    Here is a sample that illustrates how to get all roles as check boxes

    foreach (string role in Roles.GetAllRoles())
    {
        CheckBox cb = new CheckBox();
        cb.Text = role;
        Controls.Add(cb);
    }

    Can't you change the masterpage name ( which are represented as templates in Sitefinity from backend UI >> Pages >> Templates. Otherwise you may loose some page - template references which means that you have to reassign each page to the template. If 99% of the wesite is based on this masterpage this will be easy.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Laura
    Laura avatar
    311 posts
    Registered:
    25 Feb 2008
    26 Jan 2010
    Link to this post
    Yes, I meant to change the actaul page in VS such as main_3col.master to main_landing.master.  but I gues it doesn't really matter.  All the users will really be concerned about is the Template name and not the master page file name it came from.... 

    Thank you as always!
  8. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    03 Feb 2010
    Link to this post
    Hi Ivan and Gabe,

    I have a question that is kind of on the same line.

    I am wanting to have role based navigation using the Sitefinity/usercontrols/menu.ascx or tabs.ascx usercontrols.

    Is there a way to display menu items based on whether they are authenticated or not?
    Is there a way of going into a cms page api to see this?

    Also, is there a way to display menu items based on role and also assign a role to a page.

    In DotNetNuke each page has a setting where admins can assign a user role that can view/edit a page.
    Is this same functionality available in SF?

    Thanks very much
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Feb 2010
    Link to this post
    Hello sam,

    In Sitefinity you can also assign which role can view a page or not after an user has been authenticated. You can do this through backend UI >> Pages. You have to set Anonymous Access to Deny to each page you want to hide/show based on the authenticated user and his/her permissions.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
Register for webinar
9 posts, 0 answered