HowTo: Display parts of a page to anonymous users only

My ex-colleague Chris O'Brien (prolific blogger at http://www.sharepointnutsandbolts.com/) has a good post on some of the hidden gems in the SharePoint web control libraries (http://www.sharepointnutsandbolts.com/2008/03/great-controls-to-be-aware-of-when.html).

In his discussion about SPSecurityTrimmedControl he mentions some issue he has when trying to set up a section of his page to show to anonymous users, but not authenticated users. He tried:

   1: <SharepointWebControls:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AnonymousUsersOnly">
   2:     This *should* be visible only to anonymous users but it doesn't work..    
   3: </SharepointWebControls:SPSecurityTrimmedControl> 

This wasn't working (though it looks like it should). An alternative method is to use the standard ASP.NET control LoginView:

<asp:LoginView runat="server">
      <AnonymousTemplate>
                           This will be visible only to anonymous users and does work…
       </AnonymousTemplate>
       < LoggedInTemplate>
                            This will be visible only to authenticated users and does work…
       </LoggedInTemplate>
</asp:LoginView>

This works exactly as advertised.

Leave a Reply


HowTo: Display parts of a page to anonymous users only

My ex-colleague Chris O'Brien (prolific blogger at http://www.sharepointnutsandbolts.com/) has a good post on some of the hidden gems in the SharePoint web control libraries (http://www.sharepointnutsandbolts.com/2008/03/great-controls-to-be-aware-of-when.html).

In his discussion about SPSecurityTrimmedControl he mentions some issue he has when trying to set up a section of his page to show to anonymous users, but not authenticated users. He tried:

   1: <SharepointWebControls:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AnonymousUsersOnly">
   2:     This *should* be visible only to anonymous users but it doesn't work..    
   3: </SharepointWebControls:SPSecurityTrimmedControl> 

This wasn't working (though it looks like it should). An alternative method is to use the standard ASP.NET control LoginView:

<asp:LoginView runat="server">
      <AnonymousTemplate>
                           This will be visible only to anonymous users and does work…
       </AnonymousTemplate>
       < LoggedInTemplate>
                            This will be visible only to authenticated users and does work…
       </LoggedInTemplate>
</asp:LoginView>

This works exactly as advertised.

Leave a Reply