InASP. net2.0Provides many (Membership),Roles(Role ),Profiles(Custom configuration) and other features. These features are built onProvider. This seriesArticleWill unveil the mystery of this model and guide you to build your ownProviderModel
Before starting this article, we will give a general summary.ProviderThe overall relationship behind the model shows how it solves the problems faced by every developer.
ProviderReason for model requirements
Let's first introduce the requirementsProviderThe reason for the model.
Consider a typical user registration and login system that allows you to establish, manage, and authenticate users. Developers need to writeCodeTo perform the necessary data access. For example, to check whether the user is valid, you have to create a login page to allow the user to enter the creden required for the login page. Then, you need to query the database to check whether the creden entered by the user are valid, determine whether the user can access the site based on the result.
This is a good practice, but have you considered rewriting these similar code more than once? Almost every business applicationProgramDevelopers must repeat these steps. If we roughly review this process, you may use the traditional "Copy-Paste "or component to reuse the code. Indeed, this solution is great in some cases, but what should you do if the basic database and verification model are different? Of course, you can modify the code to generate new components.
Isn't it possible for developers to provide a logic model with a wide range of commonalities in their applications? This model is not affected by the basic database or business logic processing. This is what we will introduce in this article.ProviderModel
ProviderGlance
The figure above showsProviderThe stack model of the model, at the bottom, you can specify the use of your specific database, which is used to ultimately store real data. The database here can beSQL Server,AccessDatabase, or other types suchOracleDatabase
The database is not directly exposed in your code. In order to separate it from the application, all access to the database will go throughProviderClass. For exampleSQL ServerStores data and uses the member relationshipMembershipThen you can useSqlmembershipproviderClass to encapsulate the business logic for database access. You can also create your ownProviderModel
The next layer is a class -- the class isMembership class(For otherProviderModel, there will be corresponding classes, such as user configuration correspondingProfileClass, corresponding to role managementRolesClass ).User Interface (the interface here can beWebForm, suchLogin,CreateuserwizardLogin Control) UseMembershipClass.MembershipClass will callProviderClass,.
UseProviderThe model can be called onlyCreateuser ()AndValidateuser ()These two tasks are similar to creating and verifying users. They are simple and neat, aren't they?
ASP. net2.0AvailableProvidersModel
Listed belowASP. net2.0ProvidedProvidersModel
MemberProvider(Membership provider): Verify the user of your site
RoleProvider(Role provider): Authorize users on your site
ArchivesProvider(Profile provider): Used to personalize the settings of your site
NavigationProvider(Sitemap provider): Use the site map (Web. sitemap) To navigate to your site
SessionProvider(Session state store provider): Stores data using basic databases.Session
As you can see, integrating them will make developers' tools easier, and they can all be implemented throughWeb. configConfigure to point to your own database
Summary
This article summarizesASP. net2.0OfProviderModel. In the next section, we will look at the execution process of these models.