Show Content to Anonymous Users/Hide Content from Logged in Users

A while ago I made a quick post about the SPSecurityTrimmedControl and how it can easily be used to hide any content based on permissions. (

Jason Coleman brought up a good question which was “How can you hide content from someone who is logged in?” (As opposed to anonymous access.) This could be used to hide registration links, sign in links, and other custom content you might have.

The answer is very simple. We just add javascript that hides controls or that changes the look of elements on the page into the SPSecurityTrimmedControl. This javascript would only render when users have the required level of permissions so anonymous users would see the content, but it would be hidden for logged in users. 🙂

Simple Example:

<div id=“RegistrationLink”>REGISTER</div>

<SharePoint:SPSecurityTrimmedControl ID=SPSecurityTrimmedControl1  PermissionsString=CreateAlerts runat=server>
<script type=”text/javascript” language=”javascript”>
document.getElementById(RegistrationLink).style.display = “none”;

IMPORTANT NOTE: Of course you called also use the ASP login view control to do this as well, and this is probably recommended since it’s designed to do just that. LoginView Control:

I am merely trying to illustrate other uses for the above control because I like it so much. 🙂

Hope this helps someone,
Richard Harbridge

Explore posts in the same categories: Administration, Code, Tips and Tricks

Tags: ,

You can comment below, or link to this permanent URL from your own site.

One Comment on “Show Content to Anonymous Users/Hide Content from Logged in Users”

  1. Raghavendra Says:

    Excellent! Thanks for the useful post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: