I want to inherit SqlMembershipProvider, setup the membership settings to use the derived custom provider, and prohibit someone from calling Membership.CreateUser()
and Membership.DeleteUser()
.
I have an external application that will offer a user add/delete mechanism that does more than what built-in Membership does.
I was able to override the CreateUser() and DeleteUser() to throw NotSupportedExceptions
when Membership.CreateUser() or Membership.DeleteUser() is called.
I then tried 2 custom methods and had each invoke base.CreateUser()
and base.DeleteUser()
but got null exceptions. I believe the issue is the base methods are only accessible by the overridden functions and not the custom ones.
My code is below:
public class UserMembershipSQL : SqlMembershipProvider
{
internal MembershipUser CreateUserCustom(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
//do stuff here -- not accessible by Membership.CreateUser
//currently throws a null exception even though all parameters are set properly
return base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
}
internal bool DeleteUserCustom(string username, bool deleteAllRelatedData)
{
//do stuff here -- not accessible by Membership.DeleteUser
return base.DeleteUser(username, deleteAllRelatedData);
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new NotSupportedException();
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new NotSupportedException();
}
}
Thanks.