Reputation: 1423
I am working on asp.net MVC core application. I have custom database with users and roles tables. I want to use asp.net identity with custom tables so that I don't have to use aspnetusers, aspnet roles tables. How to do it with asp.net identity and asp.net core
Upvotes: 3
Views: 6913
Reputation: 15191
Good luck with that! :) I have just gone through that process last few days. I've got it to work but its really painful at some stages.
In short:
This link will help you: https://www.asp.net/identity/overview/extensibility/overview-of-custom-storage-providers-for-aspnet-identity
Upvotes: 2
Reputation: 1957
You can use Cookie Middleware Authentication.
In your Startup.cs you add
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "MyCookieMiddlewareInstance",
LoginPath = new PathString("/Account/Unauthorized/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
In your code, after you validate username and password, to login you call
await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal);
and to signoff
await HttpContext.Authentication.SignOutAsync("MyCookieMiddlewareInstance");
Please see article at Microsoft website for more details
Upvotes: 1