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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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