これは本質的にSteven'sと同じ答えですが、完全に実装されたクラスがあります(他の誰かがこれをすべて書く時間を節約するため)。
public class CompositeProvider : MembershipProvider
{
public override string ApplicationName
{
get
{
return _provider.ApplicationName;
}
set
{
_provider.ApplicationName = value;
}
}
private MembershipProvider _provider
{
get
{
// Insert your logic here to change between multiple providers
if(SomeCondition == true)
return Membership.Providers["AspNetSqlMembershipProvider"];
else
return Membership.Providers["AspNetSqlMembershipProvider2"];
}
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
return _provider.ChangePassword(username, oldPassword, newPassword);
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
return _provider.ChangePasswordQuestionAndAnswer(username, password, newPasswordQuestion, newPasswordAnswer);
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
return _provider.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
return _provider.DeleteUser(username, deleteAllRelatedData);
}
public override bool EnablePasswordReset
{
get { return _provider.EnablePasswordReset; }
}
public override bool EnablePasswordRetrieval
{
get { return _provider.EnablePasswordRetrieval; }
}
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
return _provider.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords);
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
return _provider.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
return _provider.GetAllUsers(pageIndex, pageSize, out totalRecords);
}
public override int GetNumberOfUsersOnline()
{
return _provider.GetNumberOfUsersOnline();
}
public override string GetPassword(string username, string answer)
{
return _provider.GetPassword(username, answer);
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
return _provider.GetUser(username, userIsOnline);
}
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
return _provider.GetUser(providerUserKey, userIsOnline);
}
public override string GetUserNameByEmail(string email)
{
return _provider.GetUserNameByEmail(email);
}
public override int MaxInvalidPasswordAttempts
{
get { return _provider.MaxInvalidPasswordAttempts; }
}
public override int MinRequiredNonAlphanumericCharacters
{
get { return _provider.MinRequiredNonAlphanumericCharacters; }
}
public override int MinRequiredPasswordLength
{
get { return _provider.MinRequiredPasswordLength; }
}
public override int PasswordAttemptWindow
{
get { return _provider.PasswordAttemptWindow; }
}
public override MembershipPasswordFormat PasswordFormat
{
get { return _provider.PasswordFormat; }
}
public override string PasswordStrengthRegularExpression
{
get { return _provider.PasswordStrengthRegularExpression; }
}
public override bool RequiresQuestionAndAnswer
{
get { return _provider.RequiresQuestionAndAnswer; }
}
public override bool RequiresUniqueEmail
{
get { return _provider.RequiresUniqueEmail; }
}
public override string ResetPassword(string username, string answer)
{
return _provider.ResetPassword(username, answer);
}
public override bool UnlockUser(string userName)
{
return _provider.UnlockUser(userName);
}
public override void UpdateUser(MembershipUser user)
{
_provider.UpdateUser(user);
}
public override bool ValidateUser(string username, string password)
{
return _provider.ValidateUser(username, password);
}
}