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.
-
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/…DJ.– DJ.2015-11-04 21:00:35 +00:00Commented Nov 4, 2015 at 21:00
-
Have a look at this answer: Adding ASP.NET MVC5 Identity Authentication to an existing projectSam FarajpourGhamari– Sam FarajpourGhamari2015-11-05 17:53:15 +00:00Commented Nov 5, 2015 at 17:53
-
Did you already have any kind of authentication before?Matt– Matt2019-02-27 14:30:02 +00:00Commented Feb 27, 2019 at 14:30
-
Could you please accept my answer if that solves your problem? Please please please :DHao Zhang– Hao Zhang2020-03-27 15:18:09 +00:00Commented Mar 27, 2020 at 15:18
Add a comment
|
1 Answer
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.
1 Comment
kipusoep
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!