How to add ASP.NET MVC5 Identity Authentication to existing database

1) If I want to use identity authentication, is there a reason not to use MVC template? Or is there a reason to use empty template? MVC template also provides bootstrap. Identity authentication, MVC template and bootstrap are not really related. If you create new MVC 5 application, AccountController is created for you. You can … Read more

The entity type ‘Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin’ requires a key to be defined

Basically the keys of Identity tables are mapped in OnModelCreating method of IdentityDbContext and if this method is not called, you will end up getting the error that you got. This method is not called if you derive from IdentityDbContext and provide your own definition of OnModelCreating as you did in your code. With this … Read more

ASP.NET Web API 2: How do I log in with external authentication services?

I had the same problem today and found the following solution: At first get all available providers GET /api/Account/ExternalLogins?returnUrl=%2F&generateState=true The response message is a list in json format [{“name”:”Facebook”, “url”:”/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=http%3A%2F%2Flocalhost%3A15359%2F&state=QotufgXRptkAfJvcthIOWBnGZydgVkZWsx8YrQepeDk1″, “state”:”QotufgXRptkAfJvcthIOWBnGZydgVkZWsx8YrQepeDk1″}] Now send a GET request to the url of the provider you want to use. You will be redirected to the login page of … Read more

How do I use ASP.NET Identity 2.0 to allow a user to impersonate another user?

I’ve found a solution to this problem. Basically I add claim with admin username, if this claim exists, I know that impersonation is happening. When admin wants to stop impersonation, system retrieves original username for the claims, deletes old impersonated-cookie and creates a new cookie for the admin: [AuthenticateAdmin] // <- make sure this endpoint … Read more

The entity type ApplicationUser is not part of the model for the current context

I was having this same problem. I’m doing database first development with an EDMX file. If you are using the connection string generated when adding the EDMX file in :base(“EDMXConnString”) you will most likely have this problem. I fixed this by creating a standard connection string that pointed to the database where the ASP.NET Identity … Read more

Where are the Login and Register pages in an AspNet Core scaffolded app?

It was announced during the preview of asp.net core 2.1 that the Identity UI would be moved to a new Razor Class Library. https://blogs.msdn.microsoft.com/webdev/2018/03/02/aspnetcore-2-1-identity-ui/ It is still possible to scaffold the Identity Views into your own project if you prefer local views: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio