【发布时间】:2014-07-04 13:07:42
【问题描述】:
我编写了 C# 代码来从 Active Directory 获取电子邮件。它在我的本地系统上运行良好,但托管后我没有收到电子邮件地址。以下是我已经尝试过的东西-
- 将应用程序池标识更改为
NetworkService - 启用 Windows 和 Digest 身份验证(同时启用,也逐个启用)
代码:
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "comppany.com" , "DC=compnay,DC=com", ContextOptions.Negotiate))
// tried above and below//(ContextType.Domain, System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName))
{
// validate the credentials
bool isValid = pc.ValidateCredentials(Uid, Pwd);
if (isValid)
{
try
{
using (UserPrincipal up = UserPrincipal.FindByIdentity(pc, Uid))
{
return up != null && !String.IsNullOrEmpty(up.EmailAddress) ? up.EmailAddress : string.Empty;
}
//return "Validate successfully.";
}
catch (Exception ex)
{
return ex.Message;
}
}
}
也尝试过关注-
using (var connection = new DirectoryEntry())
{
using (var search = new DirectorySearcher(connection)
{
Filter = "(samaccountname=" + Uid + ")",
PropertiesToLoad = { "mail" },
})
{
return (string)search.FindOne().Properties["mail"][0];
}
}
在 IIS7.0 中托管应用程序后,它们都不工作
请帮忙。 谢谢
【问题讨论】:
-
你试过远程调试吗?还是记录?
标签: c# iis-7 active-directory