Friday, January 2, 2009

How To: Alternative login mechanism for public MOSS Site

To start the new year I'll show you how to make an alternative login mechanism for your public SharePoint site. The solution consists of 2 parts:
  • Hide the "Sign in" link for anonymous users
  • Create a Login subsite with a redirect page.

The reason for hiding the "Sign in" link for anonymous users is obvious. If your site doesn't need a login system for anonymous users - it can be confused to show a "Sign in" link.

1) Hide the "Sign in" link
Place a SPSecurityTrimmedControl around the Welcome usercontrol within your masterpage.



The SPSecurityTrimmedControl is responsible for showing/hiding certain content, based on user rights. The Welcome usercontrol is responsible for showing the "Sign in/Welcome John Doe" link.

When you navigate to your site as an anonymous user, you'll notice that the "Sign in" link isn't visible anymore. Hmm... If we want to contribute to the site, we have to log in right? How can we login to the site if the link is not visible? Read on...


2) Create a Login subsite with a redirect page.

Create a subsite (based on the blank site template) on the toplevelsite and call it "Login". The next thing we have to do is to create a redirect page on the Login site. You can make one with the OOTB site template "Redirect Page". The "Redirect Page" page layout contains a redirect control for automatically directing readers to any specified URL.


Go into edit mode of our newly created redirect page and fill in the following URL in the Redirect URL textbox:




/_layouts/Authenticate.aspx?source=/pages/default.aspx


The authenticate page gives you the opportunity to log in to the site. The querystring source tells us where to go when the authentication process is finished.

The last thing we have to do is to set the Redirect Page as the welcome page of our "Login " site.

Conclusion
When we enter our sharepoint site as an anonymous user, we don't see a "Sign in" link anymore. If we want to contribute (read: log in) to the website - all we have to do is to navigate to http://localhost/Login.