我們已將.NET 4(可以說myIIS.xx1.mydomain.com)從.NET 4更新到4.5 更新後,我們無法從我們的某個域獲取用戶(可以說是xx3.mydomain.com)。從其他人(讓我們說xx1.mydomain.com,xx2.mydomain.com,xx5.mydomain.com)我們仍然得到用戶。 但它的工作的所有域上的.NET 4System.DirectoryServices.AccountManagement.FindAll在從.net 4更新到4.5之後出現問題
我們用下面的代碼來測試它
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;
}
}
}
的「xx3.mydomain.com」(一個不工作了)拋出以下異常:
在System.DirectoryServices.AccountManagement.UserPrincipal.get_EmailAddress()
對於我來說,它看起來像就好像它是一個訪問問題。但是如果.NET 4安裝在客戶端上,我仍然可以訪問這個域。我已經在多個域中的多個客戶端和服務器上對它進行了測試,但在.NET 4.5的所有客戶端上,此特定域不起作用。
幫助受到高度讚賞。提前感謝任何反饋和建議。