ASP.NET 中包含的提供程序大部分都是数据持久性实现的抽象,这些数据持久性实现是针对诸如配置文件或成员资格这类功能的。但是,此模型还可应用于任何其他类型的功能,这些功能可以使用多种方式进行抽象和实现。
<membership defaultProvider="PTMembershipProvider"> <providers> <add name="PTMembershipProvider" type="PTMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" description="Stores and retrieves membership 
 data using CSLA .NET business objects."/> </providers> </membership>
publicclass PTMembershipProvider : MembershipProvider ...{ publicoverridebool ValidateUser( string username, string password) ...{ bool result = PTPrincipal.Login(username, password); HttpContext.Current.Session["CslaPrincipal"] = Csla.ApplicationContext.User; return result; } Non-Implemented Members#region Non-Implemented Members // the following members must be implemented due to the abstract class MembershipProvider, // but not required to be functional for using the Login control. publicoverridebool ChangePassword(string username, string oldPassword, string newPassword) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridebool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverride MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridebool DeleteUser(string username, bool deleteAllRelatedData) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridebool EnablePasswordReset ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverridebool EnablePasswordRetrieval ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverride MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, outint totalRecords) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverride MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, outint totalRecords) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverride MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, outint totalRecords) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverrideint GetNumberOfUsersOnline() ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridestring GetPassword(string username, string answer) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverride MembershipUser GetUser(string username, bool userIsOnline) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverride MembershipUser GetUser(object providerUserKey, bool userIsOnline) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridestring GetUserNameByEmail(string email) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverrideint MaxInvalidPasswordAttempts ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverrideint MinRequiredNonAlphanumericCharacters ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverrideint MinRequiredPasswordLength ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverrideint PasswordAttemptWindow ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverride MembershipPasswordFormat PasswordFormat ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverridestring PasswordStrengthRegularExpression ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverridebool RequiresQuestionAndAnswer ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverridebool RequiresUniqueEmail ...{ get...{ thrownew NotSupportedException("The method or operation is not implemented."); } } publicoverridestring ResetPassword(string username, string answer) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridebool UnlockUser(string userName) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridevoid UpdateUser(MembershipUser user) ...{ thrownew NotSupportedException("The method or operation is not implemented."); } publicoverridestring ApplicationName ...{ get ...{ thrownew NotSupportedException("The method or operation is not implemented."); } set ...{ thrownew NotSupportedException("The method or operation is not implemented."); } } #endregion }
初始化provider
providerSection = (IndexusProviderSection)WebConfigurationManager.GetSection("indexusNetSharedCache"); ////providerSection.Providers类型是ProviderSettingsCollection // load registered provider and point provider base to the default provider providerCollection =new IndexusProviderCollection(); ProvidersHelper.InstantiateProviders( providerSection.Providers, providerCollection, typeof(IndexusProviderBase) ); //使用所提供的设置初始化给定类型的提供程序的集合。已初始化的提供程序的集合返回到providerCollection providerBase = providerCollection[providerSection.DefaultProvider];