Search code examples
c#asp.netasp.net-coreasp.net-identity

Is it possible to add ASP.NET Core Identity to a WebForms project?


I know it is possible to add ASP.NET Identity (note NOT Core) to a WebForms project. But what I want to do is add ASP.NET Core Identity to an existing WebForms project.

  1. Is this possible?
  2. If 1. is not possible, then how do I share an ASP.NET Core Identity user database between my .NET Core application and WebForms application so that I can implement https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-2.2#use-a-common-user-database

Solution

  • It is definitely possible to share the database

    Option 1: you will need to do some custom implementation since Core Identity (v3) might have a slightly different schema than .NET Framework Identity (v2). Take a look at the following link https://learn.microsoft.com/en-us/aspnet/identity/overview/extensibility/index

    You might need to also override the PasswordHasher if they are different implementations. Check the following article out: https://andrewlock.net/exploring-the-asp-net-core-identity-passwordhasher/

    Option 2: You can expose login/registering/membership functionality from your Core project and consume from your WebForm as a rest service. There are several rest security schemes and middleware.

    See:

    Those are a few quick ones. You can probably extrapolate and get some other ideas from looking at the source for Identity lib (https://github.com/aspnet/AspNetCore/tree/master/src/Identity) If you scroll down the readme you'll see different Store providers. For Option 1 you would need to essentially write a Core Store for your Web Forms Identity lib (https://archive.codeplex.com/?p=aspnetwebstack)