Understanding Microsoft Identity Namespaces (System.Web.Security, Microsoft.AspNet.Identity.Core, vs Microsoft.AspNetCore.Identity)

三世轮回 提交于 2020-01-24 22:10:05

问题


i hope somebody had a similar problem and can give be advice. I researched for quite some time but couldn't find a definitive answer.

My Set Up:

  • 1 MsSQL Database (contains the Identity Tables of System.Web.Security)
  • Many DLLs in .Net Framework (Using System.Web.Security for Log-In)
  • Multiple different Programs/Apps calling the DLLs
  • WebForms GUI in .Net Framework (Using System.Web.Security for Log-In)

What I want:

  • Use IdentityServer4 in .net Core or .Net Framework
  • Keep DLLs in .Net Framework
  • Use WebApi in .Net Core
  • Use a new GUI (f.ex. in Angular or Blazor)
  • Use the Old GUI in WebForms in parallel to the new GUI (until the new GUI is finished)

My Problem: My DLLs and Applications use System.Web.Security for User-Management (login etc.). This namespace is not supported in .Net Core, but to change all my DLLs to .Net Core is not feasible for me, because this would result in too many changes. I would like to keep them in .NetFramework.

One of My main Questions:

  • Can an App in .Net Core (f.ex. WebApi, IdentityServer4) and an App/Dlls in .NetFramework use the same Database for Identity (login, membership, etc.). In other word are "microsoft.aspnet.identity" and "microsoft.aspnetcore.identity" compatible (regarding the database) if used in different Apps/Dlls.
  • Or do I have to use one of the Identity-Namespaces in all apps/dlls to be compatible? (and therefore MUST use the same Framework in all apps/dlls)

I hope this was short and clear enough to describe my problem. Please let me know if something was unclear.

Update I just found this Post Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.EntityFramework in .NET Standard 2.0 Maybe using .Net standard in all DLLs might be an option. I will try this and see I it will work out for me. But I still don't understand if and how "microsoft.aspnet.identity" and "microsoft.aspnetcore.identity" works in a .Net Standard library.

Result: I was able to use "Microsoft.AspNetCore.Identity", "Microsoft.EntityFrameworkCore" in a .Net Standard 2.1 Library (Microsoft.EntityFrameworkCore is supported in .Net Standard 2.1 and net Core 3.0). So this is good News (I don't have to migrate all DLLs to .Net Core just for Identity. Migrating to .Net standard would be enough). But I can't reference that .Net Standard 2.1 DLL in a .Net Framework DLL/App because .Net Framework support it up to .Net Standard 2.0... So this does not fully solve the problem, but it seems to be the closest thing to what I want to do.

Update2

I am prepared to change a lot of code for this change. F.ex. the Authentication in the old WebApp so that it talks to the IdentityServer and removing everything related to System.Web(.Security) in all projects. One thing that still confuses me is "microsoft.aspnet.identity" vs "microsoft.aspnetcore.identity". Do I have to choose one of them for all projects or can I mix those namespaces (depending on the Framework of the projects) but just keep one database.

Update3 I marked an answer because it helped for answer my basic question ("it's not possible"). I will try to implement it and see it there surface more problems. But if someone has more ideas/experiences for this topic, please feel free to share it here.

Some of the sources I used:

  • No plans to port System.Web.Security it into .Net Core: https://github.com/dotnet/core/issues/838
  • Identity tables in Database have changed from 2012 to 2013: What's the diff between dbo.aspnet_Users and dbo.aspnetUsers?
  • Discussion about Membership provider not being compatible to aspnet .core: https://github.com/aspnet/AspNetCore/issues/1501
  • Video about migration with a lot of information: https://www.youtube.com/watch?v=shn3gL_UJ38
  • Discussion about about Identity and .Net Core/Standard that is similar to my problem (But it didn't help, maybe is missed something): Identity in ASP.NET MVC Framework using Identity Core
  • Guide to Migrate .Net to .Net Core: https://docs.microsoft.com/en-us/aspnet/core/migration/proper-to-2x/?view=aspnetcore-2.1
  • "Microsoft.AspNet.Identity.Core" vs "Microsoft.AspNetCore.Identity": What is the difference between Microsoft.AspNet.Identity.Core and Microsoft.AspNetCore.Identity?
  • IdentityServer4 can be in .NetFramework as well (does not have to .Net Core) https://leastprivilege.com/2017/01/15/platforms-where-you-can-run-identityserver4/ Thank you!

回答1:


Despite both having ASP.NET in the name, ASP.NET Core is an entirely different framework than ASP.NET. People don't seem to realize that this isn't just like a making a version jump: you will have to rewrite your app.

ASP.NET Membership (System.Web.Security) is deprecated and 100% unsupported in .NET Core. That's not going to change and there is no workaround here. If you want to do auth in ASP.NET Core, you'll have to start from scratch.

Since you want to use Identity Server, anyways, you can still support your legacy Web Forms app, but you'll have to move all authentication to Identity Server, and then use Identity Server as your auth mechanism in the Web Forms app. Again, this is going to require making changes to the Web Forms app. There is no other option here.

On the Identity Server side, you may opt to forgo ASP.NET Identity. Identity Server is just the auth provider; it doesn't concern itself with user management. You can technically continue to use your old user tables, but you'd have to create custom profile and user store providers for Identity Server, to enable it to do the work it needs to do. Honestly, you're better off just starting over with Identity here, than doing a bunch of work to attempt to support a user management system that was deprecated long ago.

Long and short, nothing here is trivial. If you want to do what you're talking about, you are embarking on a major project, which will require a ton of effort and changing every piece of your app. That's just the way it is. If you're not prepared for that, then stick with what you have.



来源:https://stackoverflow.com/questions/58451272/understanding-microsoft-identity-namespaces-system-web-security-microsoft-aspn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!