4.14.2 Usage: Creating A New MVC Web Application

To begin creating a new MySQL ASP.NET MVC web application, you can either:

From the MySQL toolbar, click the New Project button to open the Create new MySQL project wizard.

Figure 4.58 Creating a New Project from the MySQL Toolbar

Creating a New Project from the MySQL Toolbar

Initial steps -- Choosing the project type:

The first selection should be the type of the project. For this example, choose ASP.NET MVC Project. The first language shown in the list is C#. The new application can be created with a new solution, or you can add it to an existing solution that is already open in Visual Studio.

Step one -- Select the database connection for web authentication:

Next, set up a connection to a MySQL Database. It can be an existing database, or use the wizard to create a new database. This database stores the generated ASP.NET membership tables where the users, roles and profiles are stored. While the wizard can generate a MySQL connection string that includes your credentials, this insecure practice is not recommended since the credentials would be shown as plain text in the web configuration file. The wizard loads all available MySQL connections in the Server explorer window so you can select one to use, or you can create a new MySQL connection. By default, the MySQL Membership Provider is used for authentication in the web application. The MySQL Roles and MySQL Profiles providers are optional.

Step two -- Setup Membership provider options:

Now, set up your membership provider options. This step will define the validations performed when the user is created. Checking "Require question and answer" makes those fields mandatory. Optionally, an initial user can be created within the generated application code. These credentials can be used when authenticating in the web application for the first time.

Figure 4.59 Provider Settings Configuration

Provider Settings Configuration

Step three -- Set up the Model Connection string (optional):

Optionally, you can create a new Data Entity Model using the .NET Entity Framework (EF) object-relational mapper. Visual Studio 2010 includes EF v5.0, and Visual Studio 2013 includes EF v6.0. The wizard loads the available MySQL connections in the dropdown box. If the desired MySQL connection does not exist, then it can be created here for the model. This connection can be the same or different than the connection you selected for the Membership provider. Creating a model is optional, check the Do not include a model box to not create one. Also, the name of the model can be customized.

Figure 4.60 Model Connection String Settings

Model Connection String Settings

Step four -- Selecting tables (optional):

If a model is included (see previous step), then you have the option to select tables for the application. You can choose any number of tables, and each table will be included in the model, and a new View and Controller will be generated for each table in the generated application. The filter helps locate particular tables, but it does not change previous selections.

Figure 4.61 Database Object Selection

Database Object Selection

Finish -- Generate the application

Click Finish to generate the application.

When the application is generated, a brief description for each step is performed by the wizard and included inside the General Output panel. To see this panel, click View and select the Output option. The following screenshot shows the Solution Explorer window with all of the controllers generated by the Wizard, and it includes the General output window messages.

Figure 4.62 Solution Explorer With General Output

Solution Explorer With General Output

To run the application, either click F5 or select Run from the Debug menu. This opens the new application in your web browser:

Figure 4.63 Homepage after executing the generated application

Homepage after executing the generated application

Click Login to login using the credentials you defined earlier, or to create a new account.

Figure 4.64 Application: Login

Application: Login

After logging in, here is an example view of the Sakila addresses table:

Figure 4.65 Application: Table View

Application: Table View