生产环境中出现 DirectoryServicesComException,但本地计算机上没有 C# ASP.net
该代码在我的本地计算机上运行良好,但是当发布到服务器时,它会在
results = mySearcher.FindAll();
代码行上抛出 DirectoryServiceCOMException 。 我的函数传递两个搜索框的内容,用户可以在其中按姓名或职位查找员工:
// Bind to the users container.
string path = "LDAP://DC=DOMAIN,DC=TLD";
DirectoryEntry entry = new DirectoryEntry(path);
// Create a DirectorySearcher object.
DirectorySearcher mySearcher = new DirectorySearcher(entry);
// Set a filter for users with the name test.
mySearcher.Filter = "(&(objectClass=user)";
if (employeeName != "")
{
mySearcher.Filter = mySearcher.Filter + "(name=*" + employeeName + "*)";
}
if (position != "")
{
mySearcher.Filter = mySearcher.Filter + "(title=*" + position + "*)";
}
mySearcher.Filter = mySearcher.Filter + ")";
mySearcher.Sort = new SortOption("sn", System.DirectoryServices.SortDirection.Ascending);
// Use the FindAll method to return objects to a
// SearchResultCollection.
results = mySearcher.FindAll();
The code works great on my local machine but when published to the server it throws the DirectoryServiceCOMException on the
results = mySearcher.FindAll();
line of the code.
My function passes the contents of two searchboxes where the user can lookup an employee by name or position:
// Bind to the users container.
string path = "LDAP://DC=DOMAIN,DC=TLD";
DirectoryEntry entry = new DirectoryEntry(path);
// Create a DirectorySearcher object.
DirectorySearcher mySearcher = new DirectorySearcher(entry);
// Set a filter for users with the name test.
mySearcher.Filter = "(&(objectClass=user)";
if (employeeName != "")
{
mySearcher.Filter = mySearcher.Filter + "(name=*" + employeeName + "*)";
}
if (position != "")
{
mySearcher.Filter = mySearcher.Filter + "(title=*" + position + "*)";
}
mySearcher.Filter = mySearcher.Filter + ")";
mySearcher.Sort = new SortOption("sn", System.DirectoryServices.SortDirection.Ascending);
// Use the FindAll method to return objects to a
// SearchResultCollection.
results = mySearcher.FindAll();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能原因:
Possible reasons: