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.
In order to add a Web API Controller, you will need to Right Click the Controllers folder in the Solution Explorer and select on Add and then New Item. Now from the Add New Item window, choose the API Controller – Empty option as shown below. Then give it a suitable name and click Add.
ASP.NET Core Identity: Is an API that supports user interface (UI) login functionality. Manages users, passwords, profile data, roles, claims, tokens, email confirmation, and more.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With