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. (https://sharepointkb.wordpress.com/2008/09/02/hide-content-or-controls-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”;
</script>
</SharePoint:SPSecurityTrimmedControl>

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: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.aspx

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

Hope this helps someone,
Richard Harbridge

Advertisements
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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: