ASP.NET empowers you to develop your own storage provider and you can use it in your developed application without any further or re-coding. In this article, Aegis Softtech professionals will describe how to implement a custom MySQL ASP.NET Identity storage provider. This topic is shared to help entire ASP.NET development community and its developers across the world.
Things we will be covering in this tutorial are:
- We will create MySQL database sample using Windows Azure.
- We will use MySQL client tool for creating tables and handling your remote database on Windows Azure.
- We will replace the default ASP.NET identity storage implementation using custom MVC app project.
Creating MySQL database sample on Azure
- 1. You need to log in to Windows Azure Management portal.
- 2. Then click on ‘new’ and select STORE from the list.
This is how it will appear
3. Select ClearDB MySQL Database from Choose and Add-on wizard and click on next.
4. As we are making a sample, select the free plan and name it to IdentiyMySQLDatabase. After selecting nearest region you can click on next.
5. Accept the legal terms to accomplish database development.
6. Now you can manage your developed database from Add-ons tab available in management portal
7. Now click the Connection Info to avail database connection information
8. You need to copy the connection string by simply clicking on the copy button. You can keep it safe for later use in MVC application.
ASP.NET Identity Tables development in DatabaseYou have to install MySQL Workbench tool for connecting and handling database.
- 1. Complete the installation of mySQL workbench tool via MySQL downloads.
- 2. Release the app and select MySQLConnections + button for adding new connection. You can use your saved connection string here.
- 3. Once the connection is established, you need to open a new Query tab. Later paste MySQLidentity.sql commands into query and implement it for creating database tables.
- 4. You can now use ASP.NET identity tables hosted on Azure
Develop a MVC application project
- 1. For adding new project, you need to right click the Asp.Net.Identity.MySQL solution.
- Now select Visual C# from Add New Project dialog, and then Web and then click Asp.Net Web Application. Give a name to your project and click OK; we have used IdentityMySQLDemo as a name.
3. Your new Asp.Net development Project dialog will show you a lsit of templates, you can select MVC template with default options and select OK.
- 4. Right click on IdentityMySQLDemo project available in Solution Explorer and select Manage NuGet Packages. Then type Identity.EntityFramework in search text box and uninstall the package.
- 5. By right clicking the IdentityMySQL demo project, you can select ASPNET.Identity.MySQL project by clicking Add > Reference > Solution > Projects. Click OK
- 6. You can replace your all references from the project using Microsoft.AspNet.Idenity.EntityFramework; with using AspNet.Identity.MySql;
- 7. Set ApplicationDbContext in your IdentityModels.cs from MySQLDatabase
8. You can now open the file- IdentityConfig.cs. Replace UserManager in the ApplicationUserManager.create method with below code:
9. You need to open your Web.config file to replace your DefaultConnection string with this entry replacing the yellow marked values with the MySQL databse connection string created previously:
Running your developed Asp.net app and connecting to MySQL Database by following these steps:
- 1. Right click your IdentityMySQLDemo project and click Set as Startup Project.
- 2. For developing and running the app, you need to press ctrl+ F5 keys.
- 3. You can click the Register tab that you will notice on the top
- 4. Fill the details and click on Register.
5. You have registered successfully as a new user and logged in.
6. You can check all user entries by going back to MySQL workbench tool and reviewing IdentityMySQLDatabase table’s content.
This tutorial is shared to assist Asp.net development community and developers in implementation of a custom MySQL Asp.net identity storage provider without re-doing alterations in the application by Ethan Millar & Aegis Softtech .net Development Company.
For further information, mail us at [email protected]