References
http://msdn.microsoft.com/en-us/library/6tc47t75%28v=VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms366730.aspx
Question
In the 2nd link precisely under heading Create a Custom Membership Provider
you will note that they mention this
You will need to create a custom membership provider that supports both your custom membership user type, and your custom membership data store. The GetUser and CreateUser methods of the custom membership provider can be written to return objects of the custom membership user type.
below is my custom membership user with custom fields
Custom Membership User
public class CustomMembershipUser : MembershipUser
{
//private fields for internal use
private bool _isMarried;
private bool _hasLicense;
private string _address;
private int _userId;
//public fields for use by end user
public int UserId
{
get { return _userId; }
set { _userId = value; }
}
...
Custom Membership Provider
public class CustomMembershipProvider : MembershipProvider
{
.....
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new NotImplementedException();
}
....
I did exactly what they told me to do, return membership user of my custom type like this
public override **CustomMembershipUser** CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
but then i was complained by the IDE that Cannot Change return type when overriding MembershipProvider.CreateUser. So what am i supposed to do now,
- Create another method with same parameters and return custom membership user?
- I don't have any need for password question, security question fields how do i get rid of them?
You need to return a MembershipUser
instance in the function which is the return type for it. Currently it isn't returning what it is supposed to return.
There is a good tutorial at codeproject : Custom Membership Providers. You might find it helpful in understanding where you aren't getting right.
You should not create a new method that return CustomMembershipUser.
You should have only MembershipUser CreateUser(...) in the custom membership provider. Before your return you need to cast the CustomMembershipUser to be MembershipUser.
E.g. out following when you return.
return (MembershipUser)new CustomMembershipUser();
来源:https://stackoverflow.com/questions/8090350/implementing-custom-membership-user-and-custom-membership-provider