Active Directoryからユーザーの名と名前(フルネーム)を取得する際に問題が発生しました。コードは以下のとおりです。
私のローカルでプロジェクトを実行しても問題ありません。好きなようにデータを取得できます。プロジェクトをリモートサーバーに公開した後、名と名前(フルネーム)を取得することはできません。ドメイン名とユーザー名を取得するだけです。どうすれば修正できますか?
private string GetNameSurname()
{
string[] retVal;
//Pull the username out of the domain\user string.
retVal = Page.User.Identity.Name.Split(new string[] { @"\"},StringSplitOptions.RemoveEmptyEntries);
DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + retVal[0] + "/" + retVal[1]);
string namesurname = (string)userEntry.Properties["fullname"].Value;
//return retVal[1];
//retVal[1] gives username.
//retVal[0] gives domain name
return namesurname;
}