Thursday, June 17, 2010

Hide sign in link for anonymous users in SharePoint internet facing sites

A frequent request when you enable anonymous access to any of your SharePoint zone is to hide the "Sign In" hyper link which comes in top right corner of the page. Probably the business might have a request to have an intranet site for all authenticated users and an anonymous site for their customers, so showing a "sign in" link is irrelevant by all means.
Let try eliminating this link in somewhat supported way.

Anatomy of the control
This link comes from user control called welcome.ascx in 12hive\TEMPLATE\CONTROLTEMPLATES, this user control has a feature menu template which is responsible for rendering the menu containing "sign in as different user" and "Sign out" options

Rendering of Feature Menu Template


Scroll towards the end of the file you will find the following section

<SharePoint:ApplicationPageLink runat="server" id="ExplicitLogin" ApplicationPageFileName="Authenticate.aspx" AppendCurrentPageUrl=true
Text="<%$Resources:wss,login_pagetitle%>" style="display:none" Visible="false" />

This application link control is responsible for rendering the "Sign in" control

Take a look at the control tag for its implementation, its visible attribute is marked as false, this will become visible only if the user is not authenticated and the site has anonymous access enabled.
Steps to remove sign in link
  1. Create a new folder under 12hive\TEMPLATE\CONTROLTEMPLATES say 12hive\TEMPLATE\CONTROLTEMPLATES\Foo
  2. Copy the welcome.ascx to this Foo folder (lets stick to best practice of not touching the OOB files).
  3. Comment this ApplicationPageLink section in this copied file under \CONTROLTEMPLATES\Foo

<!--<SharePoint:ApplicationPageLink runat="server" id="ExplicitLogin"
ApplicationPageFileName="Authenticate.aspx" AppendCurrentPageUrl=true
Text="<%$Resources:wss,login_pagetitle%>" style="display:none" Visible="false" /> -->

4. Open your custom master page and modify the mapping to our new user control as below

<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Foo/Welcome.ascx" %>

There you go .. . Do an iisreset and refresh the anonymous page

Less custom code, less bugs and more solid solutions.


No comments: