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.

7 comments:

Anonymous said...

hi Sven,

firstly, thanks for your post - this was exactly what i was after! merci.

however, question of you - is the subsite necessary? could you not just have a page which is a redirect page that does the same thing?

~Steve

Komakino said...

Hi Steve,

The subsite is not necessary. I just created it because I think it is more userfriendly for the users. That way they don't have to navigate to /pages/login.aspx but just to /login. Maybe there's a way for routing with the web.config... It's up to you - you can do whatever you want. :)

Anonymous said...

I have tried to use the SharePoint control but SharePoint Designer does not recognize the control and it breaks the page everytime. Can you please explain how to get SharePoint Designer to recognize what you are saying will work.

Thanks...

Unknown said...
This comment has been removed by a blog administrator.
Vic's Blog said...

Hi,

Here is my issue. We are unable to find a solutio for this scenario. We have the annonymous users and authenticated users. The annonymous users are expcted to go to the annonymous page where as the authenticated users has o be directly logged in to the site without going through the signin process...This requirement is very urgent and we all are stuck...Please help with a solution...

Komakino said...

If I understand it correctly - you want 1 single entry point to your public facing website for anonymous users and "authentication" users (log in automatically)?

I don't think this setup is doable.
Maybe you can use "Content Deployment", but in that case you have 2 entry points. One for the editing environment (authentication users) and one for the published environment (anonymous users).

Sven.

brandon said...

On SharePoint you want to create web application in central administration.

Next find authentication providers, followed by selecting enable anonymous,
and save.
Find web application management, select site, under anonymous policy, check deny write.

Simple orders to follow to Navigate to Site:
1. Choose Site Action
2. Select Site Setting
3. Select Site Permissions
4. And then click Anonymous Access, followed by Entire Website, then OK.


Now close all browsers and go back into the website again. Once back in if you did everything correctly you will be browsing as anonymous!

Shawn Zernik
www.internetworkconsulting.net