How to add asp.net identity to existing web api project?
Asked Answered
F

1

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.

Fox answered 4/11, 2015 at 12:48 Comment(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/…Incrust
Have a look at this answer: Adding ASP.NET MVC5 Identity Authentication to an existing projectMisdoing
Did you already have any kind of authentication before?Arvad
Could you please accept my answer if that solves your problem? Please please please :DInwardly
I
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.

Inwardly answered 16/1, 2020 at 19:27 Comment(1)
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!Parous

© 2022 - 2024 — McMap. All rights reserved.