This project has moved and is read-only. For the latest updates, please go here.

Custom Membership Provider

Sep 13, 2013 at 3:02 PM
Hello Chris,

I hope you are doing well. I have added a few fields in the aspnet_Users table e.g FirstName,LastName etc.

Wrote my CustomMembershipProvider extending the MembershipProvider class and CustomMembershipUser.

I have checked my custom membership provider and it works well on fetching the users and editing as well but i am unable to create the user.

While debugging, i realized that for create user(even i have overriden this function), my custom method aint getting called instead SqlMembershipProvider's createuser function is on the run.

Here is the full exception from log.

Application error when access /SitePages/Home.aspx, Error=Cannot insert the value NULL into column 'FirstName', table 'aspnetdb.dbo.aspnet_Users'; column does not allow nulls. INSERT fails. The INSERT statement conflicted with the FOREIGN KEY constraint "FK__aspnet_Me__UserI__22AA2996". The conflict occurred in database "aspnetdb", table "dbo.aspnet_Users", column 'UserId'. The statement has been terminated. The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource
1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Sy__stem.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) __
at System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser()
at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e)
at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Your help would be highly appriciated.

Thanks,
Shoaib Younus
Sep 13, 2013 at 4:12 PM
That is strange. Are you sure it's your custom membershipprovider that's being called for the edit and fetch, and not the standard sqlmembershipprovider? Because really all calls should go to the same membershipprovider. If they're not - double check your web.config to make sure it's pointing to your custom membership provider, and also make sure that SharePoint is set to use that configured membership provider for the zone.

If you continue to have issues, maybe debug the FBA Pack. Put a breakpoint in 'Utils.GetMembershipProvider', and make sure that it really is your membership provider being returned.
Sep 13, 2013 at 5:47 PM
Yes Chirs, I am using custom membership provider and i have made changes everywhere in the code to use custom membership provider, infact, i have change the utils' GetMembershipProvider() functions(All Functions) to use custom membership provider and its working pretty well everywhere.

The issue is only in the Membership Request webpart. When i create user using "Membership Request webpart". It calls the sqlmembership provider. I dont know where do i need to change in the code so that it can use custom membership provider instead of sql membership provider.

Configurations are all set correctly in machine.config and tokensecurity service's web.config.

Please guide.

Thanks.
Shoaib Younus
Sep 13, 2013 at 5:51 PM
Oh - I wouldn't think you'd need to change any code in the FBA Pack to use the custom membership provider - as long as you implemented all of membership provider methods and pointed the web.config to your custom membership provider, it should just work (Notice that there are no specific references in the FBA Pack to SQLMembershipProvider - all are to the base MembershipProvider).

My guess would be an issue with your web.config (which is causing the MS CreateUserWizard control to use a SQLMembershipProvider instead of your custom membership provider) - but that's the only thing I can think of.
Sep 13, 2013 at 6:21 PM
I just noticed the membership provider in the config files is using sqlmembership provider.

<membership>
  <providers>
    <add name="FBAMembershipProvider"
    __type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"__

but when i try to modify the __type property to

type = "Visigo.Sharepoint.FormsBasedAuthentication.Code.FBAMembershipProvider"

I am unable to access the site.

in the __type property . "Visigo.Sharepoint.FormsBasedAuthentication.Code" is namespace and "FBAMembershipProvider" is the custom membership provider extending MembershiProvider class.

I think the problem is now with the __type attribute.

Please suggest, how to modify the config to make the application to use custom membership provider.

Thanks.
Sep 13, 2013 at 6:44 PM
The whole line has to match the assembly reference perfectly including version and publickeytoken. You should also make sure that the assembly is in the GAC.
Sep 13, 2013 at 11:36 PM
Thanks Chris,

It worked just with one entry as advised in your reply.

I am feeling excited. Thank you ;)