Create the Login Page
The first step in creating the login page is to locate the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS
directory. From there create a new directory, for instance DEVX
, and copy the simple.master
files into that directory. After copying the files, open the login.aspx
page in Visual Studio 2005. There are three things you must change in the existing login.aspx
file for your code-behind to work.
The first change is in the @Page tag, or more specifically the Inherits attribute. This attribute needs to reflect the full class name and assembly of the class library you created previously. The second change is in MasterPageFile, which needs to include the subdirectory you just added to the simple.master file. Note that this step isn't technically required for the application example here because you don't customize the simple.master file, but in your deployment it's likely you'll customize the master to reflect the branding of your organization. The third change is to assign the ID loginBoxinstead of loginto the ASP.NET login control. This change is necessary because there are two controls with login in their names, and in the code behind file you named the control loginBox; therefore, you must rename it in your login page to ensure they match and aren't ambiguous for the compiler.
Referencing the class you created previously is a bit more challenging because it's long. The type identifier is made up of five parts with a comma separating each part:
- The full name of the class, which includes the namespace.
- The name of the assembly, which is the name of the assembly file without the period and DLL extension.
- The version number of the assembly, which should be 184.108.40.206, by default, but can be changed.
- The culture for the assembly, which defaults to neutral but can be changed.
- The publickeytoken for the assembly, which although technically it's not required for every deployment it is necessary for all assemblies installed in the GACas you're going to do with this assembly.
When you put these parts together the type name is somewhat longfor example:
CustomLoginPages.CustomLogin, CustomLoginPages, Version=220.127.116.11,
Deploy and Run
Now you're ready to deploy the code and run it. In the deployment category there are two steps: First, deploy the CustomLoginPage assembly to the web application's bin directory, or alternatively to the GAC. Second, in the web.config file modify the configuration/system.web/authentication/forms node's loginUrl attribute to point to the new location for the login.aspx page.
All that's left to do is to open a web browser to the web application and try to go to a secure pageor click the login linkto display a new login page. You'll be able to log in with your e-mail address as well as your user name. Sometimes relatively simple procedures like this one can be the difference between thousands of hours writing custom authentication providers and a handful of hours spent enhancing a page in SharePoint. Which one would you prefer?