Question

I have implemented FBA (Claim based Authentication) on Sharepoint 2010. Following are implemented.

  • Custom Login page
  • Custom Sign-in Page
  • Password recovery page (ForgetPassword.aspx)
    In ForgetPassword page user is asked to enter their email address, they used while sign-in and in code behind I am using this email to get the UserName using the Membership.GetUserNameByEmail function and then passing this username to Membership.GetUser function to get the user credential to be send through mail.

But now the code throws as exception saying "The function is not implemented". I am wondering; I am not using any custom database for which I had to create a Custom Membership Provider. Then why I am getting this error. Let me know if anyone has any clue or faced similar problem. Thanks.
Regards, Paddy

Was it helpful?

Solution

When FBA is configured for SharePoint 2010, two membership providers are defined in the web.config file - Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider (usually named i) and System.Web.Security.SqlMembershipProvider (named FBAMembership in this case). Default membership provider must be set to the former (i.e. SharePoint claims one) in order for FBA authentication to work properly.

When the line containing Membership.GetUserNameByEmail(...) is executed, the default membership provider is used and as a result SPClaimsAuthMembershipProvider.GetUserNameByEmail is called. MSDN says that this method is reserved for internal use and is not intended to be used directly from your code and according to the comment in the Community Content section it throws NotImplementedException.

You need to retrieve an instance of the SqlMembershipProvider provider from the Membership.Providers collection and then call the GetUserNameByEmail method using this instance.


I use prefixes when configuring providers in the web.config file and the retrieve them like this:

string applicationNamePrefix = "fbaProvider_";
MembershipProvider fbaProvider;

foreach (MembershipProvider provider in Membership.Providers)
{
    if (provider.ApplicationName.StartsWith(applicationNamePrefix, StringComparison.InvariantCultureIgnoreCase))
    {
        fbaProvider = provider;
    }
}

throw new InvalidOperationException("Appropriate provider was not found.");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top