Try Now
More in this section

Forums / Developing with Sitefinity / Custom Logo based on User Role

Custom Logo based on User Role

5 posts, 0 answered
  1. Laura
    Laura avatar
    311 posts
    25 Feb 2008
    08 Jul 2009
    Link to this post
    I am thinking this is a simple thing but I do need some help.

    I have a site where a user will log in and depending on who they are, will see certain pages and also have their company logo displayed. (Like a custom portal just for them).

    With one username/password per company, I will add the user to a Role (their company name) and then manage (allow/deny) pages that way using the Admin area of Sitefinity.

    However, to display the logo dynamically (to avoid having to duplicate pages across the site) can/should I utilize the photo property of the User Profile?  Then, upon login, display this photo?  

    Or, if I had many users for a company and they all belonged to the same role (CompanyA) can I associate a logo to be displayed based on their role?  [however, after further thought, if the roles are to be added by our client I will not be able to determine what the roles are named so this may not work -   I think the logo will have to be associated to the user and right now there is only one user per role. The logo can then be added under the user profile by our client and accessed that way]

    Do you have any code samples or suggestions for a control to put on the template?

    Thank you in advance.
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    18 Jul 2012
    09 Jul 2009
    Link to this post
    the simplest approach I can think of is to make the filename of the logo equal to the username (since there is only one user per role). then on page load you could do something like

    img.ImageUrl = "/images/logo/" + Page.User.Identity.Name + ".jpg"

    if there are many users per company, depending on how many companies there are you might consider using the asp.net themes to style the page, creating one theme for each company/role.

    then on page_preinit you can do something like

    if (User.IsInRole("A"))  
         Page.Theme = "A";  
    else if (User.IsInRole("B"))  
         Page.Theme = "B"

    and so on, defining the logo in css. this is the approach I used on our city website (www.mcallen.net) to show different banners and colors (while keeping the same basic site structure the same) for different departments.

    I hope that this was helpful! if you think either of these will work for you, I'd be happy to go into more detail...
  3. Georgi
    Georgi avatar
    3583 posts
    28 Oct 2016
    10 Jul 2009
    Link to this post

    I was thinking for the same approach.
    You can even do this in your master page code behind file. Just define an asp:image control, and change the image src attribute depending on the role (like SelArom suggested).

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Laura
    Laura avatar
    311 posts
    25 Feb 2008
    10 Jul 2009
    Link to this post
    Thank you very much for your answers. 

    The client will be adding new users/roles so we can not hard code anything.  But what I ended up doing is to use the avatar image as the logo for the user.  So when the user logs in, we just pull their profile picture (which can be easiy uploaded by our client using Sitefinity) on the template using a control that pull the profile.photo from the library.

    If there were dozens of users for one company you would have to upload the logo to each user and that may not be the best solution but in this case it is just one user login per company.

    I welcome any more thoughts...  Thanks for the input!

  5. sarah
    sarah avatar
    1 posts
    07 Jan 2011
    07 Jan 2011
    Link to this post

    I was having the same issue. thats the perfect answer :)

    thank you for kind information

    Sarah Johnson
    Graphics Designer
    Logo Designs Services
Register for webinar
5 posts, 0 answered