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.
How to add asp.net identity to existing web api project?
Asked Answered
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 project –
Misdoing
Did you already have any kind of authentication before? –
Arvad
Could you please accept my answer if that solves your problem? Please please please :D –
Inwardly
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") { }
}
Add a connection string in your Web.config file
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.
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.