Skip Navigation Links
Skip navigation links
Products
Support
Downloads
Press
Site Map
Satisfied Customers
All-in-one VHD
Request Demo
Contact Us
Skip navigation links
Alert Manager 2007
Extranet Collaboration Manager
How do I install ExCM?
How do I deploy to a site collection and activate ExCM - Standard Edition's features?
How do I configure forms authentication in SharePoint?
How do I create a new delegated administrator?
How do I manage users in the authorization store?
How do I manage roles in the authorization store?
How do I audit delegation activities?
How do I change the format and content of ExCM - SE e-mail messages?
How do I create a new delegation provider?
How do I invite users to join my site?
How do I allow or prevent uninvited users to join my site?
How do I enable user self-registration?
How do I obtain and apply a product license for trialware or purchased software?
How do I gather custom data from users when they register for site access?
How do I allow users to manage their own profile data?
How do I manage profile data for my site's users?
How do I enable anonymous access to Register.aspx so users can self-register?
Extranet Collaboration Manager FAQ
How do I take a custom action upon SharePoint FBA user login?
How do I leverage the FBA user registration events provided by ExCM?
How do I configure Delegation Settings in ExCM?
How do I create a user automation job?
How do I delete a user automation job?
How can I view the policies of a user automation job?
How can I update the policies of a user automation job?
How do I change the schedule of a user automation job?
How do I update the notification messages of a user automation job?
I would like to know more about user automation
How do I configure Registration Settings in ExCM?
How do I modify the login page to include the forgot my password and registration link?
How do I perform a manual installation of ExCM?
What features need to be activated to use ExCM?
What web properties are used by the ExCM application?
How do I upgrade Extranet Collaboration Manager?
A valid license could not be obtained.
General
Site Provisioning Assistant
Article Index
How do I take a custom action upon SharePoint FBA user login? 
Intended audience: Developer 
Tags: developer 
 
Multimedia demo: Watch a video demonstrating this topic.

Many of our customers have use cases where by they would like to take a specific custom action when an FBA (forms based authentication) user logs in to their SharePoint Extranet. Some examples may be to update a back-end CRM system, or redirect the user to a specific page. It is actually fairly simple to implement this logic. The Visual Studio project and source code for this article can be downloaded by clicking the download link at the bottom of this page.

First under the 12 hive, open the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS folder. Find the login.aspx file, and make a copy of it called CustomLogin.aspx. This will be our new user login page.

Next, open the web.config for your SharePoint application, find the <authentication/> element, and change it from:

    <authentication mode="Forms">
<
forms loginUrl="/_layouts/login.aspx" />
</
authentication>

to:

    <authentication mode="Forms">
<
forms loginUrl="/_layouts/CustomLogin.aspx" />
</
authentication>

Now, create a new Class Library project in Visual Studio, or alternatively download my sample project from the link below. Your project will need references to Microsoft.SharePoint.dll, Microsoft.SharePoint.ApplicationPages.dll, and System.Web.

Rename the automatically created Class1.cs to CustomLoginPage.cs. To save time and effort, the CustomLoginPage class will derive from Microsoft.SharePoint.ApplicationPages.LoginPage. Here's what the class should look like:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Security;

namespace SPSolutions.Custom
{
public class CustomLoginPage : Microsoft.SharePoint.ApplicationPages.LoginPage
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.login.LoggedIn += new EventHandler(OnLoggedIn);
}

// Fires after user has sucessfully logged in
void OnLoggedIn(object sender, EventArgs e)
{
// Get the user
MembershipUser user = Membership.GetUser(this.login.UserName);

if (user != null)
{
// Do something interesting such as redirect or update CRM
}
}
}
}

As you can see, it is a simple matter of subscribing to the base page's login control's LoggedIn event, and then taking action when that event fires. Inside the event handler, you can instantiate a MembershipUser object for the newly logged in user, and then do something interesting.

It should also be noted that the login control has three other events which may be salient to your particular use case.

  • LoggingIn - Occurs when a user submits login information, but before authentication takes place.
  • Authenticate - Occurs when a user is authentication takes place.
  • LoggedIn - Occurs when a user logs in to the web site, and has been authenticated.
  • LoginError - Occurs when a login error is detected.

Next, open the CustomLogin.aspx page created in the first step, and modify its Assembly and Page declarations to point towards the new custom code behind assembly. If you're using my sample project, your declaration will look exactly like this:

<%@ Assembly Name="SPSolutions.Custom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e9db3057acd9c0f6"%> 
<%@ Page Language="C#" Inherits="SPSolutions.Custom.CustomLoginPage" MasterPageFile="~/_layouts/simple.master"%>

Finally, place the compiled assembly into the _app_bin folder of your SharePoint web application (e.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\adventureworks.local.dev\_app_bin). Optionally, you could also place the assembly into the GAC.

Download SPSolutionsCustomLogin.zip

Questions or comments about this article? 
Post them in our software support forum (registration required).