We have updated our IIS (lets say myIIS.xx1.mydomain.com) from .NET 4 to 4.5 After updating, we can't get users from one of our domains (lets say xx3.mydomain.com). From the others (lets say xx1.mydomain.com, xx2.mydomain.com, xx5.mydomain.com) we still get the users. But it worked for all domains on .NET 4
We've used to following code to test it
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices;
using System.Security.Principal;
namespace ADTestApp
{
class Program
{
static void Main(string[] args)
{
bool exit = false;
do {
Console.WriteLine(".NET Version: " + (IsNet45OrNewer() ? "4.5" : "4"));
Console.WriteLine("enter search query");
string searchQuery = Console.ReadLine();
Console.WriteLine("querying global catalog...");
string adServer = "mydomain.com:3268";
string adContainer = "DC=mydomain,DC=com";
string serviceAccountUserName = "xx5\\myusername";
string serviceAccountPW = "mypassword";
List<string> users = new List<string>();
PrincipalContext principalContext = new PrincipalContext(
ContextType.Domain,
adServer,
adContainer,
serviceAccountUserName,
serviceAccountPW);
CustomUserPrincipal user = new CustomUserPrincipal(principalContext) { EmailAddress = searchQuery, Enabled = true };
PrincipalSearcher searcher = new PrincipalSearcher() { QueryFilter = user };
foreach (UserPrincipal p in searcher.FindAll())
{
try
{
if (p.EmailAddress != null && p.Surname != null && p.GivenName != null)
{
users.Add(p.Surname + ", " + p.GivenName + " " + p.MiddleName + " - " + p.EmailAddress);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
if (users.Count > 0)
{
Console.WriteLine("Results:");
foreach (string usr in users)
{
Console.WriteLine(usr);
}
}
else
{
Console.WriteLine("no results found");
}
}
while(exit == false);
}
public static bool IsNet45OrNewer()
{
// Class "ReflectionContext" exists from .NET 4.5 onwards.
return Type.GetType("System.Reflection.ReflectionContext", false) != null;
}
}
}
The 'xx3.mydomain.com' (the one which doesn't work anymore) throws the following exception:
at System.DirectoryServices.AccountManagement.UserPrincipal.get_EmailAddress()
For me, it looks like as if it is an access issue. But I still have access to this domain if .NET 4 is installed on the client. I've tested it on multiple clients and servers in multiple domains, but on all clients with .NET 4.5 this specific domain doesn't work.
Help is highly appreciated. Thanks in advance for any feedback and suggestions.