Monday, 30 November 2015

ASP.Net Identity 2 Creating DB Context - Step 7

> C#/.Net Samples
> .Net Authentication
> Setting up ASP.NET Identity 2 with External Logins Facebok Google Microsoft and Twitter

Step # 7

 

For other steps follow:

Setting up ASP.NET Identity 2 with External Logins Facebook Google Microsoft and Twitter


We will be working with Code First approach of Entity Framework. This will go inside IdentityHelper as well.



using System.Data.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
 
namespace Identity.WebSite.IdentityHelper
{
    public class IdentityTestingDbContext : IdentityDbContext<ApplicationUser>
    {
        public IdentityTestingDbContext() : base("IdentityTestingDB") { }
 
        static IdentityTestingDbContext()
        {
            Database.SetInitializer<IdentityTestingDbContext>(new IdentityTestingDbInit());
        }
 
        public static IdentityTestingDbContext Create()
        {
            return new IdentityTestingDbContext();
        }
    }
 
    public class IdentityTestingDbInit : DropCreateDatabaseIfModelChanges<IdentityTestingDbContext>
    {
 
        protected override void Seed(IdentityTestingDbContext context)
        {
            PerformInitialSetup(context);
            base.Seed(context);
        }
 
        public void PerformInitialSetup(IdentityTestingDbContext context)
        {
            // initial configuration will go here
        }
    }
}