[Original] custom Membership, KSPMembership released, supports multi-database (mysql/oracle/sqlserver)

Source: Internet
Author: User

We believe that everyone is familiar with Membership. A set of user management tools released in the net 2.0 era. The problem is that Microsoft's official Membership is only made for SqlServer. If your system needs to use Mysql or Oracle, it will not work well, although some other Membership can support Mysql or Oracle, none of them are integrated yet.

After so many projects, some projects use SqlServer, some projects use Oracle, and some projects use Mysql, and these MIS Projects basically use Membership, this is why you think of creating a Membership that supports multiple databases at the same time. This Membership is a standard Membership, just like Microsoft's official one. Your original code can be used without any changes.

The following describes the basic ideas of this project:

1. Custom Membership needs to be inherited from the MembershipProvider class. The MembershipProvider class is an abstract class. Generally, you only need to implement the methods in these classes to complete your own Membership, my custom Membership is KSPMembership.

2. multi-database support is layered in a custom Membership. Calling can support multi-database DAL. Ibatis.net is used to support multiple databases.

3. There are many tables in the Membership database that comes with Microsoft. Some tables are useless after analysis. Here, there are four Membership-related tables, Application (Application table ), role, User, and UserInRole)

Let's take a look at how to use it. Take ASP. NET MVC2 and MySql as an example:

1. Execute the SQL statement for table creation to create the four tables. The SQL statement is included in the attachment package.

2. Open vs2008, create an ASP. NET MVC2 project (the same is true for mvc1), and copy all DLL files in the component package to the bin directory.

3. Modify the Web. config file,

A. Add the following content to the <deleetask> node:

     <appSettings>
        <add key="KSPDBType" value="oracle"/>
        <add key="KSPAPPName" value="MoleCart"/>
    </appSettings>

 

Note: kspdbtype indicates your database type. It can be any string in MySQL, Oracle, or sqlserver and is case-insensitive. kspappname indicates your application name.

B. Add the following under the <connectionstrings> node:

     <connectionStrings>
        <add name="KSPDB" connectionString="server=127.0.0.1;database=kingsiteshop;user id=root;password=;charset=utf8"/>
    </connectionStrings>

 

Note: This database connection is prepared for membership. Note that kspdb is writable and cannot be changed.

C. Add the following changes to the <system. Web> node:

Code
 <Membership defaultprovider = "kspmembershipprovider"
Userisonlinetimewindow = "15">
<Providers>
<Clear/>
<Add
Name = "KSPMembershipProvider"
Type = "KingSite. Purview. KSPMembershipProvider, KingSite. Purview"
EnablePasswordRetrieval = "false"
EnablePasswordReset = "true"
RequiresQuestionAndAnswer = "true"
RequiresUniqueEmail = "true"
PasswordFormat = "Hashed"
MaxInvalidPasswordAttempts = "5"
MinRequiredPasswordLength = "6"
MinRequiredNonalphanumericCharacters = "0"
PasswordAttemptWindow = "10"
WriteExceptionsToEventLog = "true"
/>
</Providers>
</Membership>
<RoleManager enabled = "true" cacheRolesInCookie = "true" cookieName = ". ASPROLES"
DefaultProvider = "KSPRoleProvider">
<Providers>
<Clear/>
<Add autogenerateschema = "true" writeExceptionsToEventLog = "true"
Name = "KSPRoleProvider" type = "KingSite. Purview. KSPRoleProvider, KingSite. Purview"/>
</Providers>
</RoleManager>

 

4. Compile the MVC website project in VS2008 and select your ASP. net mvc project, and then click the project menu-ASP.. NET configuration, open the website configuration page that comes with.

5. If everything is normal, you will see it.

6. Congratulations, you can customize Membership to work. You can modify the database type by modifying the KSPDBType node in the configuration file. It is very convenient, different projects can be configured as different databases.

7. KSPMembership passed the test in c #3.5, Mysql 5.1, Oralce 10g, and SqlServer 2008.

8. Download The KSPMembership package.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.