1

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

Pradeep Nair
  • 69
  • 2
  • 15
  • They are stored in the regular sql database which gets created. Although the password is stored as hashed, I am able to login in successfully. The problem is when I try to get the username using the email address entered by user "string textUserName = Membership.GetUserNameByEmail(txtemailid.Text);" it throws error, which I have mentioned above.thanks Paddy – Pradeep Nair Jan 17 '11 at 14:24
  • 1
    I have not created any custom membership provider. I have included "System.Web.Security" as using and on page load I am checking all those parameter and if the user provided correct email id I want to reset the password and send that to user using MembershipUser.ResetPassword(). I hope I understood your question correctly. Thanks Paddy – Pradeep Nair Jan 17 '11 at 16:50

1 Answers1

1

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.");
Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111