I'd like to try and use ASP.NET Core MVC or Web API at my workplace but we have just Active Directory to authentication and authorization. Is there any solution to solve it with an on premise AD or we have to change for Java? I know this question is not original but I'd like to get a simple answer to it, please.
Asked
Active
Viewed 9,176 times
2 Answers
11
Microsoft has released pre-release version for System.DirectoryServices
. You can get it from NuGet package manager using this command:
Install-Package System.DirectoryServices -Version 4.5.0-preview1-25914-04
This is working fine for me till now.

Vadim Ovchinnikov
- 13,327
- 5
- 62
- 90

p4ulinux
- 329
- 5
- 14
9
As of today, System.DirectoryServices
is not available in ASP.NET Core yet. You can read more here.
In the meantime, you can use Novell.Directory.Ldap.NETStandard
. For example,
public bool ValidateUser(string domainName, string username, string password)
{
string userDn = $"{username}@{domainName}";
try
{
using (var connection = new LdapConnection {SecureSocketLayer = false})
{
connection.Connect(domainName, LdapConnection.DEFAULT_PORT);
connection.Bind(userDn, password);
if (connection.Bound)
return true;
}
}
catch (LdapException ex)
{
// Log exception
}
return false;
}
Since it has too many moving pieces, I have created a sample project at GitHub.

Vadim Ovchinnikov
- 13,327
- 5
- 62
- 90

Win
- 61,100
- 13
- 102
- 181
-
Thanks for your answer. It seems to me Microsoft abandoned its users who cannot use Azure AD. I do not understand this great fuss for it. – Sándor Hatvani Aug 08 '17 at 19:03
-
It's scheduled to release with ASP.NET Core 2.1 (karelz added this to the 2.1.0 milestone on Dec 16, 2017). Your starter kit looks great, thanks for sharing. – Alexey Mar 15 '18 at 12:00
-
Hi, old thread but System.DirectoryServices is compatible with dotnet core now :) – albin May 18 '20 at 13:56