dotConnect for DB2 Documentation
In This Topic
    Using ADO.NET Implementation of ASP.NET Identity 1 for DB2
    In This Topic

    ASP.NET Identity is a new system of user authentication and authorization, that continues the evolution of ASP.NET membership system, and is used in the Visual Studio 2013 or Visual Studio 2013 Update 1 project templates for ASP.NET MVC, Web Forms, Web API and SPA. You can read more on ASP.NET Identity in Microsoft documentation.

    dotConnect for DB2 enables you to employ an implementation of ASP.NET Identity for DB2 database using either ADO.NET or Entity Framework functionality in your web applications. This allows you to use such ASP.NET Identity benefits as unit-testable user authentication system, social login support, OWIN integration, etc. This tutorial demonstrates creating an ADO.NET implementation of ASP.NET Identity.

    To complete this tutorial you need Visual Studio 2013 or Visual Studio 2013 Update 1 installed. For Visual Studio 2013 Update 2 or higher see Using ADO.NET Implementation of ASP.NET Identity 2 for DB2.

    In order to create an ASP.NET MVC 5 application using dotConnect for DB2 for storing identity information, perform the following steps:

    1. In the Add New Project dialog box expand Visual C# on the left, then Web, and then select ASP.NET Web Application. Name your project, for example, "AspNet_Identity_Application" and then click OK.

      Add New Project dialog box
    2. In the New ASP.NET Project dialog box, select the MVC template with the default options (that includes Individual User Accounts as authentication method) and click OK.

      New ASP.NET Project dialog box

    3. In Solution Explorer, right-click your project and select Manage NuGet Packages from the shortcut menu. In the search text box dialog, type "Identity.EntityFramework". Select this package in the list of results and click Uninstall. You will be prompted to uninstall the dependency package EntityFramework. Click Yes since we will no longer this package on this application.

    4. Add references to the necessary dotConnect for DB2 assemblies:

      • Devart.Data.dll
      • Devart.Data.DB2.dll
      • Devart.Data.DB2.Web.Identity.dll

      For ASP.NET Identity 1 you need to add the reference to the Devart.Data.DB2.Web.Identity.dll, having the revision number 0, and installed to the Program Files\Devart\dotConnect\DB2\Web\ASP.NET Identity 1 folder

    When creating an ASP.NET application, using ASP.NET Identity, you can use the existing ASP.NET Identity functionality as is or customize this functionality. For example, you may add storing some custom information about the user. In our tutorial we will demonstrate both options.

    - Using Existing ASP.NET Identity Functionality

    First, you need to create a schema that will store information about users. To do it, execute the Install_identity_tables.sql script, which goes with dotConnect for DB2. By default, this script is in the Program Files\Devart\dotConnect\DB2\Web\ASP.NET Identity 1 folder. You can also copy this script from the Identity Database Script chapter of this topic. After this perform the following steps:

    1. In Visual Studio remove the IdentityModels.cs (or IdentityModels.vb for Visual Basic) file that is in the Models folder, from the project.
    2. In the Controllers project folder open the AccountController.cs (or AccountController.vb for Visual Basic) file.

      Replace

      using Microsoft.AspNet.Identity.EntityFramework;
      
      
      Imports Microsoft.AspNet.Identity.EntityFramework
      
      

      with:

      using Devart.Common.Web.Identity;
      using Devart.Data.DB2.Web.Identity;
      using ApplicationUser = Devart.Common.Web.Identity.IdentityUser;
      
      
      Imports Devart.Common.Web.Identity
      Imports Devart.Data.DB2.Web.Identity
      Imports ApplicationUser = Devart.Common.Web.Identity.IdentityUser
      
      

      Replace the constructor code:

              public AccountController()
                  : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
              {
              }
      
      
      	Public Sub New()
      		Me.New(New UserManager(Of ApplicationUser)(New UserStore(Of ApplicationUser)(New ApplicationDbContext())))
      	End Sub
      
      

      with

      	public AccountController()
      		: this(new UserManager<ApplicationUser>(new DB2UserStore()))        
      	{
      	}
      
      
      	Public Sub New()
      		Me.New(New UserManager(Of ApplicationUser)(New DB2UserStore()))
      	End Sub
      
      
    3. In the web.config file of your project, replace the default connection string with your DB2 one.

      <add name="DefaultConnection" connectionString="user id=db2admin;server=db2;database=SAMPLE;" providerName="Devart.Data.DB2" />
      	

    + Extending ASP.NET Identity Functionality

    - Checking Application

    Now we can run our application and check if everything works correctly.

    1. Run the application by pressing CTRL+F5.

      Getting started page
    2. Switch to the Register tab on the top of the page.

      Registration page

      For an example with extended ASP.NET Identity functionality the page looks like the following:

      Registration page (with e-mail)
    3. Enter a new user name and password (and email - if you have created an example with extended ASP.NET Identity functionality) to the corresponding boxes and click the Register button.
    4. The new user is now registered and logged in.

      User is registered
    5. After this you may use an appropriate database tool to connect to the database where the user data is stored and verify that the data is stored correctly.

    + Identity Database Script

    See Also

    Using Entity Framework Implementation of ASP.NET Identity 1 for DB2  | Using Entity Framework Implementation of ASP.NET Identity 2 for DB2  | Using ADO.NET Implementation of ASP.NET Identity 2 for DB2