Open Visual Studio and create a new project, of MVC 4 Web Application type, and configure the project to use .NET Framework 4.5.
Choose the template and view engine that you like. This tutorial is using the Internet Application Template with the Razor view engine. Optionally, here you can add a unit test project by checking Create a unit test project.
Add references to the
MySql.Web assemblies. The assemblies chosen
must match the .NET Framework and Entity Framework versions
added to the project by the template.
Add a valid MySQL connection string to the
web.config file, similar to:
<add name="MyConnection" connectionString="server=localhost;UserId=root;password=pass;database=MySqlSimpleMembership;logging=true;port=3305;" providerName="MySql.Data.MySqlClient"/>
Under the <system.data> node, add configuration information similar to the following:
<membership defaultProvider="MySqlSimpleMembershipProvider"> <providers> <clear/> <add name="MySqlSimpleMembershipProvider" type="MySql.Web.Security.MySqlSimpleMembershipProvider,MySql.Web,Version=22.214.171.124,Culture=neutral,PublicKeyToken=c5687fc88969c44d" applicationName="MySqlSimpleMembershipTest" description="MySQLdefaultapplication" connectionStringName="MyConnection" userTableName="MyUserTable" userIdColumn="MyUserIdColumn" userNameColumn="MyUserNameColumn" autoGenerateTables="True"/> </providers> </membership>
Update the above configuration with valid values for the following properties: connectionStringName, userTableName, userIdColumn, userNameColumn, and autoGenerateTables.
userTableName: Name of the table to store the user information. This table is independent from the schema generated by the provider, and it can be changed in the future.
userId: Name of the column that stores the ID for the records in the userTableName.
userName: Name of the column that stores the name/user for the records in the userTableName.
This property must match a connection string defined in
must be set to
false if the table to
handle the credentials already exists.
Update your DBContext class with the connection string name configured.
Go to the SimpleMembershipInitializer class contained in the InitializeSimpleMembershipAttribute.cs file that is located in the Filters/ folder. Look for the method call “WebSecurity.InitializeDatabaseConnection”, and update the parameters with the configuration for connectionStringName, userTableName, userIdColumn and userNameColumn.
If the database configured in the connection string does not exist, then create it.
After running the web application, the following screen is displayed on success:
If the application executed with success, then the generated schema will be similar to the following:
To create a user, click Register on the generated web page. Type the desired user name and password, and then execute the registration form. This redirects you to the home page with the newly created user logged in, as shown near the top-right side of the page:
The data for the newly created user can be located in the