How To Implement Mysql ASP.NET Identity

banner

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

img

3. Select ClearDB MySQL Database from Choose and Add-on wizard and click on next.

img

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.

img

5. Accept the legal terms to accomplish database development.

img

6. Now you can manage your developed database from Add-ons tab available in management portal

img

7. Now click the Connection Info to avail database connection information

img

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.

img

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
img

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

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.

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

8. You can now open the file- IdentityConfig.cs. Replace UserManager in the ApplicationUserManager.create method with below code:

img

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:

img

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

5. You have registered successfully as a new user and logged in.

img

6. You can check all user entries by going back to MySQL workbench tool and reviewing IdentityMySQLDatabase table’s content.

img

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]

Empower your Business with Team Aegis, CONNECT NOW!
captcha

Scale your Business with our Software Services Now!
Related article

While talking about the framework, programmers and development team always wish to make best use of such platform that allows them to leverage latest

In Asp.net ajax, we have AsyncFileUpload control for uploading files asynchronously.

DMCA Logo do not copy