atypical
atypical

Reputation: 1100

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

I try to make a simple web application. There will be very few users(one or two). No need to make complicated membership stuff. I need just basic login process. I use Visual Studio 2013

I made some research on the internet and found something about ASP.NET Identity. However i could not found anything about how to install Identity tables to my own mssql database.

I used ASP.NET membership before and it was easy to install tables by using aspnet_regsql.exe and adding some codes to web.config

But now i am really confused with Identity stuff. It uses a default database to store users. But in my server there will be my sql database that stores both my datas and user datas.

How can i combine these two databases into one? How can I install Identity tables to my own database and configure my Project to use it?

Upvotes: 3

Views: 3744

Answers (2)

Jinesh Patel
Jinesh Patel

Reputation: 1

You should use Entity Framework you can take different approach like code first ,Model First DB First.

It will make much easier process for you.

Here is 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

Upvotes: 0

MisterJoe
MisterJoe

Reputation: 61

It sounds like you just want the Identity tables to use the same database as the rest of your application. If you're using a new Identity project in Visual Studio 2013, it should be using Entity Framework, which simplifies things significantly.

You should be able to make this happen by making sure the Identity code uses the same connection string as your own database context. If you change the "DefaultConnection" string in Web.config to point to your own database, Entity Framework will take care of the rest.

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

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

and change the string in base().

Again, the magic of Entity Framework is that it'll automatically create the tables and relationships it needs without requiring you to build them yourself. EF6 is also really good about handling versioning when there are multiple contexts, so you shouldn't get any "model changed" errors unless you got rid of the __MigrationHistory table.

Upvotes: 1

Related Questions