Search code examples
active-directoryasp.net-core-2.1

How to use Active Directory Authentication in ASP.NET Core?


I am using the ASP.NET Core 2.1 React SPA Microsoft template.

I want to use Active Directory for user authentication. Our server runs on a corporate network using Active Directory domain identities.

How can I do it?


Solution

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

    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. If you will only run this on a Windows server, then you can install and use the Microsoft.Windows.Compatibility NuGet package.
    2. Use the third-party Novell.Directory.Ldap.NETStandard.

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