If you want to skip the background and fluff and got straight to the solution, click here.
The new Identity model for ASP.NET provides a lot of benefit over the previous Membership framework. There is a great article discussing many of the details and how to get started at http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity. Identity uses Entity Framework 6, and when you add a new project (MVC5 or WebForms 4.5), models and context are created for you. A new connection is created using LocalDB (named “DefaultConnection”), and basic code (including the user interface) is scaffolded for you so you can get started right away without too much trouble. Pretty slick!
I recently rewrote my home owner’s association website (http://www.rdhoa.net) with ASP.NET MVC5 and Entity Framework 6.1 taking advantage of the new Identity model. I used Code First, creating a context that did not use the default connection, but instead a new connection (still using LocalDB), since I didn’t want to mix my application data and Identity data. This worked great until I went to publish my work to Azure. LocalDB isn’t supported in Azure (for a number of reasons), and having two different LocalDBs in my application meant that I would have to create two different Azure databases to support my app. While this is most likely the appropriate separation of concerns for larger applications, my little HOA site only has two users, and maybe 2 MB of data. Seemed like a waste of Azure credits to me.
Merging the Databases
After some bing/googling, and spending more than my fair share of time on the ASP.NET/Identity site, it appeared that I would have to recreate the entire Identity data base in code to use my other connection, or change my context to use the default connection. Neither of these options interested me, so I decided to just try something really basic.
The answer? Simply open the IdentityModels.cs file in the Models directory (this works for both MVC and WebForms) and change the constructor for the ApplicationDbContext to use your specific connection.
public class ApplicationDbContext :
public static ApplicationDbContext Create()
return new ApplicationDbContext();