How to use my own database in ASP.NET Identity (WebForms)

I am trying to create a simple web application. There will be few users (one or two). No need to create complex memberships. I need a simple registration process. I am using Visual Studio 2013

I did some research on the internet and found something about ASP.NET Identity. However, I couldn't find anything on how to set Identity tables to my own mssql database.

I used to use ASP.NET membership and it was easy to set tables using aspnet_regsql.exe and add some codes to web.config

But now I am really confused about the Identity stuff. It uses the default database to store users. But my server will have my sql database that stores both my data and user data.

How can I merge these two databases into one? How do I set Identity tables to my own database and configure my project to use?

+3


source to share


2 answers


It looks like you just want the Identity tables to use the same database as the rest of your application. If you are using a new Identity project in Visual Studio 2013, it must use the Entity Framework, which will make things much easier.

You must do this by making sure that the Identity code uses the same connection string as your own database context. If you change the "DefaultConnection" line in the Web.config to point to your own database, Entity Framework takes care of the rest.

If you got rid of the DefaultConnection, you can change the string used in IdentityModels.cs (in your project's Models folder) to your custom string. Look for:



public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)

      

and change the line in base ().

Again, the magic of the Entity Framework is that it will automatically create the tables and relationships it needs without having to create them yourself. EF6 is also very good at handling versions when there are multiple contexts, so you shouldn't get any "changed models" unless you get rid of the __MigrationHistory table.

+1


source


You have to use Entity Framework, you can use other approach like code first, model first first.

This will make the process easier for you.

Here are some good links.



How to install

http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net- mvc-application

0


source







All Articles