且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 ASP.NET Core 中使用 Active Directory 身份验证?

更新时间:2023-02-17 12:20:47

***的方法是使用 Windows 身份验证.但是,这只有在您运行它的服务器加入域(或受信任域)时才有效.

The best way is to use Windows authentication. However, that will only work if the server you run this on is joined to the domain (or a trusted domain).

如果没有,那么您将必须使用表单身份验证,用户输入他们的用户名和密码,然后您通过 LDAP 在代码中对 AD 进行身份验证.在 .NET Core 中有两种方法可以做到这一点:

If not, then you will have to use Forms Authentication, where the user enters their username and password, and you authenticate against AD in your code via LDAP. There are two ways to do this in .NET Core:

  1. 如果您只在 Windows 服务器上运行它,那么您可以安装和使用 Microsoft.Windows.Compatibility NuGet 包.
  2. 使用第三方Novell.Directory.Ldap.NETStandard.

这个问题上有两个答案描述了如何实施这两种解决方案.

There are two answers on this question that describe how to implement both solutions.