7

I have 2 projects in my solution. First one is simple mvc project and the other one is web api. There was no pre-written code in web api. I put all logics myself. Now I want to add asp.net identity in the web api project. How can I do that? Thanks.

4
  • I've had this link for a while in case i encounter that problem. Not sure if is what you looking for but could give you a hint. asp.net/identity/overview/migrations/… Commented Nov 4, 2015 at 21:00
  • Have a look at this answer: Adding ASP.NET MVC5 Identity Authentication to an existing project Commented Nov 5, 2015 at 17:53
  • Did you already have any kind of authentication before? Commented Feb 27, 2019 at 14:30
  • Could you please accept my answer if that solves your problem? Please please please :D Commented Mar 27, 2020 at 15:18

1 Answer 1

2

In your web api project, you can do this: 1. Create a DbContext class that looks like this:

public class DataContext : IdentityDbContext<IdentityUser>
{
    public DataContext() : base("ConnectionStringLocal") { }
}
  1. Add a connection string in your Web.config file

  2. In Package manager console, do Enable-Migrations, Add-Migration IdentityUpdate, Update-Database. This will create a database that has asp.net identity built in.

Please let me know if you have additional questions.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this, I was searching the web why the add-migration command didn't generate any of the built-in aspnet identity tables. I forgot to inherit from IdentityDbContext!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.