Custom Login page for Sharepoint 2010 Mixed mode authentication

Aug 10, 2011 at 9:56 PM


In one of my previous post, I discussed about adding form authentication to your SharePoint site. I Hope it was useful ! This post is dedicated to customize the Login Screen for the SharePoint site

Recently I had to configure Windows authentication and forms authentication in SharePoint 2010. It should not have been difficult in 2010 as it have mixed mode authentication. But what lacked were enough tutorials/articles. So I thought to share it!
 
First of all we need a landing page for our application. It is good to have common landing page for windows authentication and SharePoint authentication. So that every unauthenticated request can be re-directed to single page. By default SharePoint have a dropdown to select the authentication mode and then proceeds based on selection.
Custom Login page for Sharepoint 2010 Mixed mode authentication
 
We can also have our own login page with the same functionality. I have designed something like this.
 
Custom Login page for Sharepoint 2010 Mixed mode authentication
 
You have to specify the login page URL in web.config. By default it is “/_login/default.aspx”
 
 
Note : MyLoginPage.aspx should be application page as user will not have access to SharePoint page,  as he /she is not authenticated yet.
 
As now as we have our login page ready, we need to add the code for login button and hyperlink to intranet access
1.       Forms Authentication via Login Button
2.       Windows Authentication via hyperlink ‘Click here for intranet access’
 
1.       Forms Authentication
In the event handler of login click event we can authenticate the user with the following method.
 
SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, Username, Password);
 
This method authenticates a form user by checking username and password. When the user is validated this object persists a cookie to the client for later use.
 
2.       Windows Authentication
 
LnkIntranet.NavigateUrl = Page.ResolveUrl(@"~/_windows/default.aspx?ReturnUrl=/YouLandingPage.aspx");
 
SharePoint will authentication the windows logged in user
On Success it will redirect to the ‘ReturnUrl’ page mentioned in the parameter
On Error it will redirect to ‘AccessDenied.aspx’

 

Found this article by Dhaval Shah valuable? Help by Sharing ...

  • Click on the banners at the top of article or in the right panel to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.
  • I’d be very grateful if you’d help it spread by Sharing. Below, you should find links to sharing this article on your favorite social media sites.
Related Posts by Dhaval Shah blog comments powered by Disqus