SharePoint 2007 Portal Site Hidden Login

In an on-going effort the create SharePoint template pages we have made a nice piece of code that allows us to hide the login button of the SharePoint Portal site unless users add a specific variable to the URL or unless they are logged in:

<%
SPUser currentUser = SPContext.Current.Web.CurrentUser;
string DisplayLogin = Request[“login”];
if ((currentUser != null) || (DisplayLogin != null)) {
%>
<table cellpadding=”0″ cellspacing=”0″>
<tr style=”height:0px”>
<td>
<wssuc:DesignModeConsole id=”IdDesignModeConsole” runat=”server”/>
</td>
<td>
<div>
<!–Authentication for Authors only–>
<wssuc:Welcome id=”explitLogout” runat=”server”/>
</div>
</td>
<td>
<span>
<PublishingSiteAction:SiteActionMenu runat=”server”/>
</span>
</td>
</tr>
</table>
<% } %>

The first part we use to check for a username. If none is found we can presume there is no user logged in. The second part with the DisplayLogin variable is used to check the URL for an add-on like http://www.example.com?login=login

Not that in this script it doesn’t really matter what value is set to login as long as it is not NULL,

Leave a Reply

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