ASP.NET Membership/Role providers for MySQL?

Josh Stodola picture Josh Stodola · Jan 10, 2010 · Viewed 12k times · Source

I am not at all familiar with ASP.NET membership/roles. This is my first time using it, and my first time trying ASP.NET MVC. When I create my first project for MVC, it gives me a lovely template to create an account. I was excited to see that I did not have to do this manually. However, it failed because it cannot connect to SQL Server. I do not have SQL Server, I have MySQL. Is there any easy way I can get this system to use MySQL instead, or will I have to create my own authentication?

Answer

Josh Stodola picture Josh Stodola · Jan 11, 2010

Got it figured out! Using version 6.2.2.0 of MySql Connector/Net, follow these steps...

  • Add reference to MySql.Web.dll
  • Change your <membership> in web.config to this:

    <membership defaultProvider="MySqlMembershipProvider">
      <providers>
        <clear/>
        <add name="MySqlMembershipProvider"
             type="MySql.Web.Security.MySQLMembershipProvider,
                   MySql.Web, Version=6.2.2.0, Culture=neutral,
                   PublicKeyToken=c5687fc88969c44d"
             autogenerateschema="true"
             connectionStringName="NAME_OF_YOUR_CONN_STRING"
             enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/"
         />
      </providers>
    </membership>
  • Run the Project | ASP.NET Configuration tool and click on the Security tab to test
  • Tested on ASP.NET 3.5, MySQL Server version 5.1, Windows XP 64-bit