0
我編寫了C#代碼以從Active Directory獲取電子郵件。它在我的本地系統上工作正常,但託管後我沒有收到電子郵件地址。以下是我已經嘗試過的事情 -託管後未獲取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中託管應用程序後工作
請幫忙。 謝謝
您是否嘗試過遠程調試它?或記錄? – Tarec