Sunday, October 12, 2008

Hide the “Sign in” link in the client web browser for anonymous users






do you want to hide the sign-in link on your SharePoint sites for your internet users that access it in anonymous authentication mode?


Well, there is one simple and very quick way to do this with 2 scripts in your master page using C# + JavaScript. The effect will be that the link will not be present for anonymous user, but authenticated users will see Welcome and Action menus.




In the head section of your master page place this code :




<head>
<script>
<%
Response.Write("var isAuthenticated =" +System.Web.HttpContext.Current.User.Identity.IsAuthenticated.ToString().ToLower() +";");
%>
</script>
</head>


Wrap your menu elements with a container and give it an Id :






<td id="MenuElements" class="ms-MenuElements">
<wssuc:Welcome id="IdWelcome" runat="server" EnableViewState="false"></wssuc:Welcome>
<PublishingSiteAction:SiteActionMenu runat="server" />
</td>




At the end of your master page place this javaScript code :






<script>
if(!isAuthenticated){
document.getElementById('MenuElements').style.display="none";
}
</script>




And it's done !



Warning :




Don't forget to replace the in line code in the master page later, by an User Control or a Custom control, as the in line code will fail if the master page is customized...

No comments:

Post a Comment