问题描述
我创建了一个使用 System.DirectoryServices.AccountManagement 针对 Active Directory 验证凭据的服务.我需要针对本地域和受信任域验证凭据.在我的计算机上运行时,本地域和受信任域的验证凭据的响应时间都很快.当我将此服务移至我们的服务器时,本地域响应很快,但受信任域响应非常慢(20 - 30 秒).
I've created a service that validates credentials against Active Directory using System.DirectoryServices.AccountManagement. I need to validate credentials against the local domain as well as a trusted domain. The response time for validating credentials is fast for both the local and trusted domain when run on my computer. When I move this service to our server, the local domain response is fast however, the trusted domain response is very slow (20 - 30 seconds).
我还发现,如果我将 PrincipalContext 中的域名从 NetBios 名称更改为 DNS 名称,它可以纠正服务器上的性能问题.
I've also found that if I change the domain name in the PrincipalContext from the NetBios name to the DNS name it corrects the the performance problem on the server.
这里有一些例子
PrincipalContext context = new PrincipalContext(ContextType.Domain, sNetBiosName)
context.ValidateCredentials(sUsername, sPassword)
在服务器上,使用 NetBios 名称执行上述操作需要 20-30 秒
On the server, the above will take 20-30 seconds using the NetBios Name
PrincipalContext context = new PrincipalContext(ContextType.Domain, sDNSName)
context.ValidateCredentials(sUsername, sPassword)
使用 DNS 名称,响应时间为 0-2 秒
Using the DNS name the response is 0-2 seconds
关于需要在服务器上设置什么以使用 NetBios 名称加速此操作的任何想法?
Any ideas on what needs to be setup on the server to speed this up using the NetBios name?
推荐答案
众所周知,NetBIOS 在大网络中速度很慢.这里解释 NetBIOS 名称解析的工作原理.通常,Windows 会按以下顺序解析 NETBIOS 名称.
NetBIOS is notoriously slow in the big network. Here explains how the NetBIOS name resolution works. Normally, Windows tris to resolve the NETBIOS name in the following order.
- 本地缓存
- lmhosts 文件
- WINS 服务器
- 网络广播
因此,您可以看到可以提高 NetBIOS 名称解析速度的一件事是编辑服务器上的 lmhosts 文件,这样您就可以完全摆脱网络问题.按照这个 Microsoft KB 将您的域和 PDC 添加到您的 lmhosts 文件中.
So, you can see one thing that you can improve the NetBIOS name resolution speed is to edit the lmhosts file on your server, so that you can take the network completely out of the equation. Follow this Microsoft KB to add your domain and PDC to your lmhosts file.
这篇关于使用 NetBios 名称的受信任域的 PrincipalContext.ValidateCredentials 速度较慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!