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>
<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>
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...
Labels: C#, development, JavaScript, scripting, SharePoint


6 Comments:
why not use a security trimmed control instead?
You mean that way ?
<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageLists">
Place your control(s) here
</SharePoint:SPSecurityTrimmedControl>
Unfortunatly, there is no item in SPBasePermissions Enumeration that specifies if user is authenticated or not.
You don't need a SPBasePermissions Enumeration that specifies if user is authenticated or not. The unauthenticated user dosen't have the right to ManageLists, so it's working.
Ok, then Authenticated users that cannot manage lists will not see the "Sign in" link... :-)
Try this
< asp:LoginView runat="server">
< LoggedInTemplate>
authenticated users content
</LoggedInTemplate>
<AnonymousTemplate>
anonymous content
</AnonymousTemplate>
</asp:LoginView>
"asp:LoginView" is the most simplest and streight forward means of rendering Authanticarted and Anonymous content respectivly.
Salute..
Post a Comment
Subscribe to Post Comments [Atom]
Links to this post:
Create a Link
<< Home