Related Documentation Download this Manual
PDF (US Ltr) - 5.5Mb
PDF (A4) - 5.5Mb
EPUB - 4.7Mb
HTML Download (TGZ) - 4.6Mb
HTML Download (Zip) - 4.6Mb

MySQL Connector/Net Developer Guide  /  ...  /  Creating and Configuring a New Project

5.6.2 Creating and Configuring a New Project

  • Open Visual Studio and create a new project, of MVC 4 Web Application type, and configure the project to use .NET Framework 4.5.

    Figure 5.13 Simple Membership: New Project

    Simple Membership: New Project

  • 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.

    Figure 5.14 Simple Membership: Choose Template and Engine

    Simple Membership: Choose Template and Engine

  • Add references to the MySql.Data, MySql.Data.Entities, and 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:

  • Under the <> node, add configuration information similar to the following:

    <membership defaultProvider="MySqlSimpleMembershipProvider">
  • 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.

    • connectionStringName: This property must match a connection string defined in web.config file.

    • autoGenerateTables: This 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:

    Figure 5.15 Simple Membership: Generated Home Page

    Simple Membership: Generated Home Page

  • If the application executed with success, then the generated schema will be similar to the following:

    Figure 5.16 Simple Membership: Generated Tables

    Simple Membership: Generated Tables

  • 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:

    Figure 5.17 Simple Membership: Logged In

    Simple Membership: Logged In

  • The data for the newly created user can be located in the UserProfile and Webpages_Membership tables.

Download this Manual
PDF (US Ltr) - 5.5Mb
PDF (A4) - 5.5Mb
EPUB - 4.7Mb
HTML Download (TGZ) - 4.6Mb
HTML Download (Zip) - 4.6Mb
User Comments
Sign Up Login You must be logged in to post a comment.