如果您从成员资格提供程序派生并创建自己的自定义提供程序,则可以实现非常少的属性集。
public class CustomMembershipProvider : MembershipProvider
{
private string _appName;
private bool _EnablePasswordReset;
private bool _EnablePasswordRetrieval;
private int _MaxInvalidPasswordAttempts;
private int _MinRequiredNonalphanumericCharacters;
private int _MinRequiredPasswordLength;
private int _PasswordAttemptWindow;
private MembershipPasswordFormat _PasswordFormat;
private string _PasswordStrengthRegularExpression;
private bool _RequiresQuestionAndAnswer;
private bool _RequiresUniqueEmail;
public override string ApplicationName
{
get
{
return this._appName;
}
set
{
this._appName = value;
}
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new NotImplementedException();
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotImplementedException();
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
throw new NotImplementedException();
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new NotImplementedException();
}
public override bool EnablePasswordReset
{
get { return this._EnablePasswordReset; }
}
public override bool EnablePasswordRetrieval
{
get { return this._EnablePasswordRetrieval; }
}
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new NotImplementedException();
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new NotImplementedException();
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new NotImplementedException();
}
public override int GetNumberOfUsersOnline()
{
throw new NotImplementedException();
}
public override string GetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
throw new NotImplementedException();
}
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
throw new NotImplementedException();
}
public override string GetUserNameByEmail(string email)
{
throw new NotImplementedException();
}
public override int MaxInvalidPasswordAttempts
{
get { return this._MaxInvalidPasswordAttempts; }
}
public override int MinRequiredNonAlphanumericCharacters
{
get { return this._MinRequiredNonalphanumericCharacters; }
}
public override int MinRequiredPasswordLength
{
get { return this._MinRequiredPasswordLength; }
}
public override int PasswordAttemptWindow
{
get { return this._PasswordAttemptWindow; }
}
public override MembershipPasswordFormat PasswordFormat
{
get { return this._PasswordFormat; }
}
public override string PasswordStrengthRegularExpression
{
get { return this._PasswordStrengthRegularExpression; }
}
public override bool RequiresQuestionAndAnswer
{
get { return this._RequiresQuestionAndAnswer; }
}
public override bool RequiresUniqueEmail
{
get { return this._RequiresUniqueEmail; }
}
public override string ResetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override bool UnlockUser(string userName)
{
throw new NotImplementedException();
}
public override void UpdateUser(MembershipUser user)
{
throw new NotImplementedException();
}
public override bool ValidateUser(string username, string password)
{
//put your db code here.
}
}
然后你需要修改你的 web.config 文件来调用你的新提供者
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="MembershipExample.Providers.CustomMembershipProvider, MembershipExample"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
如果您有任何特定的基于角色的安全性,您还可以实现自己的自定义角色提供程序