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;
internal void HideStatusBar()

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


Author: Doug Ware

Atlanta based entrepreneur, author of many SharePoint books and videos, leader of Atlanta .NET user group, founder of InstantQuick, and SharePoint MVP.


  • Trevor

    March 16, 2010, 2:50 am

    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).


  • --Doug

    March 19, 2010, 12:08 pm

    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.

  • Anon

    June 15, 2010, 6:01 am

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


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

    Mai Omar
    Senior Solutions Developer

  • Parwej Pathan

    August 5, 2010, 1:13 am


    I think “HideTheRibbon” is a class which would contain the code given by Doug. He just took that for registering the scripts. If you do not want that. you can use typeof(Page).

    Doug, please correct me if wrong.


  • Jessica

    January 12, 2012, 5:45 pm

    Hi Guys,

    Question? Does the hiding the ribbon from Menu has to do with permissions like maybe owner need to change some permission so as only end users cannot see this? I think it would be great rather than getting coding involve. Any ideas?

Comments are closed