Sunday, June 26, 2011

Hiding the Ribbon for Anonymous Users

If the SharePoint site is intended to be used as public internet site you might wanna show it only for authenticated users, so regular anonymous users won't ever notice it's a SharePoint site.

I've found a couple of articles describing how to do that:
http://blogs.microsoft.co.il/blogs/itaysk/archive/2010/04/23/hiding-the-ribbon-for-anonymous-users.aspx
http://www.topsharepoint.com/hide-the-ribbon-from-anonymous-users

Basically in all posts how to hide ribbon either ASP .NET LoginView control or SPSecurityTrimmedControl are used. Each of them has it's own issues.

Using ASP .NET LoginView makes page editing not convenient. In order to correctly edit page Editor should click "Edit Page" twice.

Using SPSecurityTrimmedControl requires to set a list of permissions needed to view Ribbon and it's not obvious which security mask should be used.

Also in both cases Front-end guys need to wrap each editor specific control in one of these controls. It means that there might be e.g. 10 LoginView or 10 SPSecurityTrimmedControl controls on the page.

Another solution would be to use 2 master pages - one for the authenticated users, another - for anonymous. It's quite easy to maintain. One master page (auhtoring) should have all SharePoint specific stuff (ribbon, scripts, etc). Another page (runtime) should not have any of that. Important: both master pages should have all ContentPlaceHolder's which are used by page layouts.

Switching between master pages is performed in code. You can decide the place where to put it. You might want create control and put it on both master pages. In my case all our page layouts was inherited from our custom class. Master page switching code should be put in OnPreInit method. It could look like this:
protected override void OnPreInit(EventArgs e)
{
        base.OnPreInit(e);
        SwitchMasterPageIfNeeded();
}
private void SwitchMasterPageIfNeeded()
{
        if (SPContext.Current != null && SPContext.Current.Web.CurrentUser != null)
        {
                MasterPageFile = "CustomAuthoring.master";
        }
}


Of course it's up to you which solution to choose. But it's good to know that now you have one more way to go.

No comments:

Post a Comment