SharePoint Authenticated User Panel

When using SharePoint 2007 (MOSS) or SharePoint 2010 as a web content management system, it’s common to have pages show different content to logged in users and anonymous users.

Sometimes you can achieve what you want via audiences or security trimming, but often I find it’s easier to use an overloaded panel that you can include in your page layouts or master pages.  You can then set public properties to determine who the content renders for (anonymous users, specific roles, etc).


public class AuthenticatedPanel : Panel { public bool ShowForAnonymous { get; set; } public bool ShowForAuthenticated { get; set; } public string ShowForRole { get; set; } protected override void Render(HtmlTextWriter writer) { if (ShowForAnonymous) { base.Render(writer); return; } if (ShowForAuthenticated &&

HttpContext.Current.User.Identity.IsAuthenticated) { base.Render(writer); return; } if (!String.IsNullOrEmpty(ShowForRole) &&

HttpContext.Current.User.IsInRole(ShowForRole)) { base.Render(writer); return; } } }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>