In Visual Studio 2010 (VS2010) when you create a new Web Application Project using the default Web Template “ASP.NET Web Application” it creates an Account folder with the files Login.aspx, Register.aspx and ChangePassword.aspx.
These are files/pages for ASP.NET Membership which is ASP.NET’s built-in user handling. I have never used Membership before but have been curious to, so I saw this as my cue to do so. However since I’m running MySQL as my database server I knew I had some extra installing and configuring to do.

Now several hours later I have finally figured out what I needed to do…

1) Install the latest version of MySQL Connector/NET. Visual Studio support is from version 6.3 which is currently only available in beta, current version when writing this is 6.3.2 beta.

2) Use the MySQL Website Configuration Tool, follow instructions found by clicking this link. This tool will modify necessary configuration files (have not checked which, maybe only web.config) to use MySQL Membership, Roles, User Profile and/or Session State.

Important: (this took me quite some time to figure out) the MySQL Website Configuration Tool icon only shows up in the Solution Explorer if you create a Web Site Project in VS 2010. It does not show if you create a Web Application Project. I have reported this as a bug to MySQL.

The only workaround I found to use a Web Application instead of using a Web Site was to create a temp Web Site project, run the MySQL Web Configuration Tool and then use copy and paste to move changes from web.confg to my Web Application Project. I have provided these changes at the end of this post.

3) Done!

I am running Windows 7 64-bit, Visual Studio 2010 and MySQL Connector/NET 6.3.2 beta, but according to this thread other people with other versions of VS seems to be having the same problem.

These are the changes that are made to web.config:

  <connectionStrings>
    <remove name="LocalMySqlServer" />
    <add name="LocalMySqlServer" connectionString="server=localhost;User Id=root;database=users;password=xxx" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
<system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <membership defaultProvider="MySQLMembershipProvider">
      <providers>
      <clear />  
      <remove name="MySQLMembershipProvider" />
        <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="MySQL default application" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enablePasswordRetrieval="True" enablePasswordReset="True" requiresQuestionAndAnswer="False" requiresUniqueEmail="False" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
      </providers>
    </membership>
    <profile defaultProvider="MySQLProfileProvider">
      <providers>
        <clear />
        <remove name="MySQLProfileProvider" />
        <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" />
      </providers>
    </profile>
    <roleManager enabled="false" defaultProvider="MySQLRoleProvider">
      <providers>
        <clear />
        <remove name="MySQLRoleProvider" />
        <add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.3.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" />
      </providers>
    </roleManager>
  </system.web>