Click here to Skip to main content
Click here to Skip to main content
Go to top

Setting up MySql Membership with Visual Studio 2010

, 11 Oct 2010
Rate this:
Please Sign up or sign in to vote.
Setting up MySql membership provider with .NET Framework 4.0 and VS 2010

Introduction

This article will help in setting up the MySql membership provider with Visual Studio 2010.

Background

Membership provider will help in automatically setting up the login functionality that comes with .NET Framework.

Prerequisites

  • MySql server should be installed on the local machine or on the remote machine with which you have access.
  • We need a database to which we will connect to test the membership provider after configuring.

Following Steps Will Help in Setting Up the MySql Membership Provider with .NET

  • Download and install the fully-managed ADO.NET driver for MySQL from here version 6.3.4+
  • You might have to close down the Visual Studio development env. before starting the install.

    MySqlConnecterSetup.JPG

  • After installation, you can confirm that the MySql assemblies are present in C:\WINDOWS\assembly folder like in the image below:

    MySqlAssembly.JPG

  • Configure a database in MySql server, I have created a "Test" database on localhost, User as "root" and password as "rootpassword", I will be using these same credential in connection strings configuration.
  • Put the following code for connection string in web.config:
    <connectionStrings>
    <remove name="LocalMySqlServer"/>
       <add name="LocalMySqlServer" 
            connectionString="Datasource=localhost;
                              uid=root;
                              Pwd=rootpassword;
                              Database=test;" 
            providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
  • Put the following code for Membership provider, Profile Provider and Role Provider. Check that you refer to the correct connection string name in the below config.
    <membership defaultProvider="MySqlMembershipProvider">
    <providers>
    <clear />
      <add name="MySqlMembershipProvider" 
           type="MySql.Web.Security.MySQLMembershipProvider, 
                 MySql.Web,Version=6.3.4.0,
                 Culture=neutral,
                 PublicKeyToken=c5687fc88969c44d" 
           connectionStringName="LocalMySqlServer" 
           enablePasswordRetrieval="false" 
           enablePasswordReset="true" 
           requiresQuestionAndAnswer="false" 
           requiresUniqueEmail="true" 
           passwordFormat="Hashed" 
           maxInvalidPasswordAttempts="5" 
           minRequiredPasswordLength="6" 
           minRequiredNonalphanumericCharacters="0" 
           passwordAttemptWindow="10" 
           applicationName="/" 
           autogenerateschema="true" />
    </providers>
    </membership>
    <profile>
    <providers>
    <clear />
      <add type="MySql.Web.Security.MySQLProfileProvider, 
                 MySql.Web,Version=6.3.4.0,
                 Culture=neutral,
                 PublicKeyToken=c5687fc88969c44d" 
           name="MySqlProfileProvider" 
           applicationName="/" 
           connectionStringName="LocalMySqlServer" 
           autogenerateschema="true" />
    </providers>
    </profile>
    <roleManager enabled="true" defaultProvider="MySqlRoleProvider">
    <providers>
    <clear />
      <add connectionStringName="LocalMySqlServer" 
           applicationName="/" 
           name="MySqlRoleProvider" 
           type="MySql.Web.Security.MySQLRoleProvider,
                 MySql.Web,Version=6.3.4.0,
                 Culture=neutral,PublicKeyToken=c5687fc88969c44d" 
           autogenerateschema="true" />
    </providers>
    </roleManager>
  • Open machine.config from "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG" in the connection string section, add the following code:

    <connectionStrings>
    <add name="LocalMySqlServer" 
    connectionString="Datasource=localhost;
                      uid=root;
                      Pwd=rootpassword;
                      Database=test;" />
    </connectionStrings>
  • In same machine.config, check and modify the providers for Membership, Profile and Role also check that connectionStringName attribute points to correct connection string name. Don't delete any of the config settings that are present by default in these provider sections, just add the following lines between provider sections.
    <membership>
    <providers>
      <add name="MySQLMembershipProvider" 
           type="MySql.Web.Security.MySQLMembershipProvider, 
                 MySql.Web, Version=6.3.4.0,
                 Culture=neutral,
                 PublicKeyToken=c5687fc88969c44d" 
           connectionStringName="LocalMySqlServer" 
           enablePasswordRetrieval="false" 
           enablePasswordReset="true" 
           requiresQuestionAndAnswer="true" 
           applicationName="/" 
           requiresUniqueEmail="false" 
           passwordFormat="Clear" 
           maxInvalidPasswordAttempts="5" 
           minRequiredPasswordLength="7" 
           minRequiredNonalphanumericCharacters="1" 
           passwordAttemptWindow="10" 
           passwordStrengthRegularExpression="" 
           autogenerateschema="true"/>
    </providers>
    </membership>
    <profile>
    <providers>
      <add name="MySQLProfileProvider" 
           type="MySql.Web.Profile.MySQLProfileProvider, 
                 MySql.Web, Version=6.3.4.0,
                 Culture=neutral,
                 PublicKeyToken=c5687fc88969c44d" 
           connectionStringName="LocalMySqlServer" 
           applicationName="/" />
    </providers>
    </profile>
    <roleManager>
    <providers>
     <add name="MySQLRoleProvider" 
          type="MySql.Web.Security.MySQLRoleProvider,
                MySql.Web,
                Version=6.3.4.0,
                Culture=neutral,
         PublicKeyToken=c5687fc88969c44d" 
         connectionStringName="LocalMySqlServer" 
         applicationName="/" />
    </providers>
    </roleManager>
  • Go to Visual Studio, click Project->ASP.NET configuration:

    AspNetConfig.JPG

  • ASP.NET Web Application Administration will open in a new window, click on security tab you can now create User, Roles and Access rules
  • You can also check with the database in MySql that has been configured with the project with the list of *aspnet* tables, these are auto generated in the database.

    tables.JPG

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

deepaktripathi
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
Questiona question PinmemberkeyHu6-Jan-14 4:38 
AnswerRe: a question Pinmemberdeepaktripathi6-Jan-14 8:59 
Questionthanks a lot PinmemberkeyHu6-Jan-14 4:13 
QuestionWeb Site Administration Tool - Error PinmemberRadek.Szymanski10-Dec-12 9:12 
QuestionPublicKeyToken Pinmembernasuru829-Oct-12 20:27 
GeneralMy vote of 4 Pinmemberalessandro pungitore21-Mar-12 0:46 
GeneralMy vote of 5 Pinmembermeltamps22-Feb-12 15:32 
GeneralUnable to initialize provider. Missing or incorrect schema. Mysql Provider Pinmemberkokomantequilla26-Nov-10 23:11 
GeneralRe: Unable to initialize provider. Missing or incorrect schema. Mysql Provider Pinmemberdeepaktripathi16-Dec-10 1:48 
GeneralMy vote of 4 Pinmembertonym00112-Nov-10 10:07 
AnswerRe: My vote of 4 Pinmemberdeepaktripathi16-Nov-10 0:13 
GeneralThanks for sharing PinmemberHemant.Kamalakar13-Oct-10 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 11 Oct 2010
Article Copyright 2010 by deepaktripathi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid