Show Login for Anonymous user and Logout for Authenticated users

Here is my requirement: I want to Show Custom Log-in button for Anonymous user, and once logged in I want to show the Log-out for Authenticated users.

Here is the implementation part.

1. create your own Log-in and Log-out button images, place them under: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES

Important: Do not forget to set the images security property, otherwise you will get Log-prompt even though you enabled anonymous access. Here is the screen shot.

2. Edit the individual page if you want for ONLY one page / or Master page if you want these buttons to appear in every page

3. Place the below code:

<div id="RegistrationLink"><img src="_layouts/images/login.gif" /></div>
<SharePoint:SPSecurityTrimmedControl ID=SPSecurityTrimmedControl1  PermissionsString=BrowseDirectories runat=server>
<script type="text/javascript" language="javascript">
document.getElementById("RegistrationLink").style.display = "none";
<img src="_layouts/images/logout.gif" />

4. you are done! Here are the result screenshots.

Before Login:

After Login:

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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