Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Customize a SharePoint Login Page : Page 3

Go beyond the complexities of working with SharePoint, and discover how to create a custom login page that you can associate with unique code.


advertisement
Membership Provider Configuration
Perhaps the best place to start is by briefly reviewing the settings in the web.config file for the web application to make sure that you have the enableSearchMethods attribute set as mentioned previously. This code snippet should be in the web.config file for the web application hosting the forms authentication:

<membership defaultProvider="AD"> <providers> <add name="AD" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="EmailConnect" connectionUsername="DEMO\Administrator" connectionPassword="123" attributeMapUsername="UserPrincipalName" enableSearchMethods="true"/> </providers> </membership>

Note that you'll need to reference your connection string name, and you'll need to use your credentials. Make sure that the enableSearchMethods attribute is set.



Login Page Code-Behind
With the membership provider set up it's time to create a project to hold the code-behind for the login page. Begin by creating a new Visual Studio 2005 Class library project with an appropriate name, such as CustomLoginPage. Remove the class1.cs file; add a new class file, CustomLogin.cs; and add to that file these contents:

using System; using System.Web.Security; using System.Web.UI.WebControls; namespace CustomLoginPage { public class Login : Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase { protected System.Web.UI.WebControls.Login loginBox; protected override bool AllowAnonymousAccess { get { return true; } } protected override bool AllowNullWeb { get { return true; } } protected void Login_Click(object sender, EventArgs e) { if (AuthenticateUser(loginBox.UserName, loginBox.Password)) return; } protected bool AuthenticateUser(string emailAddr, string password) { string userName = emailAddr; MembershipUserCollection coll = Membership.FindUsersByEmail(emailAddr); if (coll != null && coll.Count == 1) { // We're doing this to force the enumerator to give us the // one and only item because there is no by int indexer foreach (MembershipUser user in coll) { userName = user.UserName; } } if (Membership.ValidateUser(userName, password)) { FormsAuthentication.RedirectFromLoginPage(userName, true); return true; } return false; } } }

You should be able to build the project by pressing Ctrl-Shift-B. You'll need to sign the login class library project to make sure that you can get an explicit reference to the correct DLL in the ASPX page. If you don't know how to assign a strong name to a project in Visual Studio you can get more information by reading Microsoft Support Document 910355: "How to Install an Assembly in the .NET Framework Global Assembly Cache" (Microsoft 2007). You don't have to install your assembly into the Global Assembly Cache (GAC), but this support document does include the signing instructions you need. Once you have a successful build you can open the Visual Studio 2005 tools' command prompt, navigate to the bin\debug directory under the project, and type:

SN –T CustomLoginPages.DLL

This command will give you the public key token that you're going to need shortly for the login page.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap