了解Microsoft身份命名空间(System.Web.Security,Microsoft.AspNet.Identity.Core和Microsoft.AspNetCore.Identity) [英] Understanding Microsoft Identity Namespaces (System.Web.Security, Microsoft.AspNet.Identity.Core, vs Microsoft.AspNetCore.Identity)

查看:626
本文介绍了了解Microsoft身份命名空间(System.Web.Security,Microsoft.AspNet.Identity.Core和Microsoft.AspNetCore.Identity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人遇到类似的问题并能提出建议。我研究了很长时间,但找不到确切的答案。

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.

我的设置:


  • 1个MsSQL数据库(包含System.Web.Security的身份表)

  • .Net Framework中的许多DLL(使用System.Web .Security for登录)

  • 调用DLL的多个不同程序/应用程序

  • .Net Framework中的WebForms GUI(使用System.Web.Security (用于登录)

  • 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)

我要什么:


  • 在.net Core或.Net Framework中使用IdentityServer4

  • 在.Net Framework中保留DLL

  • 使用.Net Core中的WebApi

  • 使用新的GUI(例如,在Angular或Blazor中使用)

  • 在WebForms中使用旧的GUI与新的GUI(直到新的GUI完成)

  • 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)

我的问题:
我的DLL和应用程序使用System.Web.Security进行用户管理(登录等)。 .Net Core不支持此命名空间,但是将所有DLL更改为.Net Core对我而言并不可行,因为这会导致太多更改。我想将它们保留在.NetFramework中。

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.

我的主要问题之一:


  • .Net Core(例如WebApi,IdentityServer4)中的应用程序和.NetFramework中的App / Dll是否可以使用同一数据库进行身份验证(登录,成员资格等)。换句话说,如果在不同的Apps / Dll中使用,则 microsoft.aspnet.identity和 microsoft.aspnetcore.identity是兼容的(关于数据库)。

  • 还是我必须在所有应用程序/ dll中使用身份命名空间之一才能兼容? (因此必须在所有应用程序/ dll中使用相同的框架)

我希望本文简短明了,足以描述我的问题。请让我知道是否不清楚。

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

更新
我刚刚发现此帖子 也许在所有DLL中使用.Net标准可能是一种选择。我将尝试一下,看看它会为我成功。但是我仍然不知道 microsoft.aspnet.identity和 microsoft.aspnetcore.identity在.Net Standard库中是否以及如何工作。

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.

结果:我可以在.Net Standard 2.1库中使用 Microsoft.AspNetCore.Identity,
Microsoft.EntityFrameworkCore(。Net Standard 2.1和Net Core 3.0支持Microsoft.EntityFrameworkCore)。因此,这是个好消息(我不必仅为身份标识而将所有DLL迁移到.Net Core。迁移到.Net标准就足够了)。
但是但我无法在.Net Framework DLL / App中引用.Net Standard 2.1 DLL,因为.Net Framework最多支持.Net Standard 2.0 ...因此,这不是完全解决了问题,但这似乎是我想要做的最接近的事情。

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

我准备为此更改很多代码。 F.ex.旧WebApp中的身份验证,以便它与IdentityServer进行通信,并删除所有项目中与System.Web(.Security)相关的所有内容。
仍然让我感到困惑的一件事是 microsoft.aspnet.identity和 microsoft.aspnetcore.identity。我是否必须为所有项目选择其中之一,还是可以混合使用这些名称空间(取决于项目的框架),但只保留一个数据库即可。

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
我标记了一个答案,因为它有助于回答我的基本问题(不可能不可能)。我将尝试实现它,并在其中看到更多问题。
但是,如果有人对这个主题有更多的想法/经验,请随时在这里分享。

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.

我使用过的一些资料:

  • 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!

推荐答案

尽管两者都以ASP.NET为名,但ASP.NET Core是与ASP.NET完全不同的框架。人们似乎并没有意识到这不只是一个版本跳转:您必须重写您的应用。

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成员资格(System.Web.Security)已被弃用,.NET Core中100%不支持。这不会改变,这里没有解决方法。如果要在ASP.NET Core中进行身份验证,则必须从头开始。

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.

由于要使用Identity Server,无论如何,您仍然可以支持您的旧版Web窗体应用程序,但是您必须将所有身份验证转移到Identity Server,然后在Web窗体应用程序中将Identity Server用作身份验证机制。同样,这将要求对Web Forms应用程序进行更改。这里没有其他选择。

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.

在Identity Server方面,您可以选择放弃ASP.NET Identity。 Identity Server只是身份验证提供程序;它与用户管理无关。从技术上讲,您可以继续使用旧的用户表,但是您必须为Identity Server创建自定义配置文件和用户存储提供程序,以使其能够执行所需的工作。坦率地说,最好是从此处的Identity开始,而不是做大量工作来尝试支持很久以前不推荐使用的用户管理系统。

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.

这篇关于了解Microsoft身份命名空间(System.Web.Security,Microsoft.AspNet.Identity.Core和Microsoft.AspNetCore.Identity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆