0

I wanted to create a custom membership provider for my asp.net mvc application, but the number of parameters in default CreateUser() method is not what I want. Because my User table is different, i want to pass my own parameters. Here is the code I used for UserCreate() Method :

public override MembershipUser CreateUser(string username,string family,string personcode, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
    {
        //
    }

and here the the error i got :

Error 2 MyMemberShipProvider.CreateUser(string, string, string, string, string, string, string, bool, object, out System.Web.Security.MembershipCreateStatus)': no suitable method found to override

Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80
  • Possible duplicate: http://stackoverflow.com/questions/5838371/asp-net-mvc-custom-membership-provider-how-to-overload-createuser – Damb May 03 '11 at 12:21
  • you mean I can implement my own MemberShipProvider by inheriting from MemberShipRpovider and override createuser like what was in the link you have sent? – Babak Fakhriloo May 03 '11 at 12:35
  • Yes, that's why I pointed to smiliar question, so you can see how they did solve it. – Damb May 03 '11 at 12:47

1 Answers1

0

A good approach is to use both the Membership Provider and the Profile provider.

The Membership provider will manage the creation of users, password validation, keeping track of who and when logs in to your app, etc.

The Profile provider allows you to manage multiple attributes for the user.

So, you will need to do the following:

  1. Implement your own Membership provider. See msdn.microsoft.com/en-us/library/f1kyba5e.aspx or msdn.microsoft.com/en-us/library/44w5aswa.aspx

  2. Implement your Profile provider (or use an existing one).
    See here msdn.microsoft.com/en-us/library/0580x1f5.aspx or msdn.microsoft.com/en-us/library/ta63b872.aspx

  3. Implement a ProfileCommon class defining the attributes you want to use for your users. Your Profile provider should know how to handle the ProfileCommon class.

For a ProfileCommon example I implemented the following for my custom MongoDB ASPNet Providers: github.com/agarcian/MongoDBASPNetProviders/blob/master/ASPNETProvidersForMongoDB/ProfileCommon.cs

  1. Configure the WebConfig sections to define your custom implementations. (See sample below)

The next examples are part of custom Membership, Role, and Profile providers I developed for MongoDB. See https://github.com/agarcian/MongoDBASPNetProviders

Here is the configuration I use in my apps to utilize my custom membership provider.

<membership defaultProvider="MongoDBProvider" userIsOnlineTimeWindow="15">
  <providers>
    <clear />
    <add
      name="MongoDBProvider"
      type="ASPNetProvidersForMongoDB.MongoDBMembershipProvider, ASPNetProvidersForMongoDB"
      connectionStringName="MongoProvidersDBConnStr"
      enablePasswordRetrieval="true"
      enablePasswordReset="true"
      requiresQuestionAndAnswer="false"
      writeExceptionsToEventLog="true"
      mongoProviderDatabaseName ="aspnetproviderdb"
      mongoProviderUsersCollectionName="Users"
      applicationName="WebUI4"
      />



  </providers>
</membership>

<roleManager defaultProvider="MongoDBProvider" enabled="true">
  <providers>
    <clear />
    <add applicationName="WebUI4"
        name="MongoDBProvider"
         type="ASPNetProvidersForMongoDB.MongoDBRolesProvider, ASPNetProvidersForMongoDB"
        connectionStringName="MongoProvidersDBConnStr"
         writeExceptionsToEventLog="true"
      mongoProviderDatabaseName ="aspnetproviderdb"
      mongoProviderUsersCollectionName="Roles"
         />
  </providers>
</roleManager>

<profile defaultProvider="MongoDBProvider" inherits="MyCompany.Security.Profile.ProfileCommon">
  <providers>
    <add
      applicationName="WebUI4"
      name="MongoDBProvider"
      type="ASPNetProvidersForMongoDB.MongoDBProfileProvider, ASPNetProvidersForMongoDB"
      connectionStringName="MongoProvidersDBConnStr"
      writeExceptionsToEventLog="true"
      mongoProviderDatabaseName ="aspnetproviderdb"
      mongoProviderUsersCollectionName="Profiles" />
  </providers>
</profile>

I hope this helps.

agarcian
  • 3,909
  • 3
  • 33
  • 55