Skip to main content

Elumenotion Blog

Go Search

 
Elumenotion > Elumenotion Blog > Posts > Code to Hide the Ribbon and Site Actions Menu for Anonymous Users
Code to Hide the Ribbon and Site Actions Menu for Anonymous Users

In Beta 2, SharePoint 2010 sites that use the publishing infrastructure have an option on the Navigation Settings page to hide the ribbon by default.

Other sites lack this functionality as does SharePoint Foundation. However, the code to do the hiding is simple:

public void HideRibbonForAnon()
{
  SPRibbon current = SPRibbon.GetCurrent(this.Page);

  if (current != null && !this.Page.Request.IsAuthenticated)
  {
    current.CommandUIVisible = false;

    SiteActions actions = SiteActions.GetCurrent(this.Page);

    if (actions != null)
    {
       actions.Visible = false;
    }
    HideStatusBar();
  }
}
internal void HideStatusBar()
{

   string script = 
      "document.onreadystatechange=fnRemoveAllStatus; function fnRemoveAllStatus(){removeAllStatus(true)};";
   this.Page.ClientScript.RegisterClientScriptBlock(typeof(HideTheRibbon), "statusBarRemover", script, true);
}

 

Comments

Where to put the code?

Hi Guys,

This seems like it would be perfect for our needs, but where do we put this code? It would be good to have this for all pages (or we can code additional scope/rules in the script whether to turn on/off).

Cheers
Trevor at 3/16/2010 2:50 AM

@Trevor

It depends, by my default would be in a control that is added to the pages in my site via DelegateControl and a Control feature.
--Doug at 3/19/2010 12:08 PM

Mai Omar

dear all.. i'm trying to hide the ribbon but this game error

(typeof(HideTheRibbon),

because HideTheRibbon seems to be class but where is it?
is there namespace needed or u created this class?

Mai Omar
Senior Solutions Developer
Website: http://www.itegyptcorp.com
Blog: http://maiomar.itegyptcorp.com
Anon at 6/15/2010 6:01 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Your Name *


Attachments
Follow me on twitter!
  Archive
  Archive (Calendar)
  Skinner Created Themes
  New Skinner Download
  New Skinner Tutorial

©  2009 Elumenotion, LLC  |   SharePoint Training, SharePoint Consulting and SharePoint Staffing
8075 Cavendish Place | Suwanee, Georgia 30024 | + 1 (888) 653-5021