implementing custom membership provider, problem with usercreate
I wanted to create a custom membership provider for my asp.net mvc application, but the number of parameters i开发者_StackOverflow社区n 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
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:
Implement your own Membership provider. See msdn.microsoft.com/en-us/library/f1kyba5e.aspx or msdn.microsoft.com/en-us/library/44w5aswa.aspx
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.aspxImplement 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
- 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.
精彩评论