RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


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.


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.configfile for the web application hosting the forms authentication:

<membership defaultProvider="AD">
    <add name="AD" 
      System.Web, Version=, Culture=neutral, 

Note that you'll need to reference your connection string name, and you'll need to use your credentials. Make sure that the enableSearchMethodsattribute 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 : 
      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)) 
        protected bool AuthenticateUser(string emailAddr, 
          string password)
          string userName = emailAddr;
          MembershipUserCollection coll = 
          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\debugdirectory 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.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date