-3
Active Directoryを使用しているWebアプリケーションがあります。 パラメータ(ユーザー、パスワード、および独自のドメイン)で認証ドメインを実行する関数を作成します。 determinatラインで は、以下の関数として、messagem「予期しないエラー」が表示されます。C#を使用しているActive Directoryで疑問がある
public bool IsAuthenticated(string domain, string username, string pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
try
{
//Bind to the native AdsObject to force authentication.
---> This Line occurred error
**object obj = entry.NativeObject;**
---> Line Above occurred error
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
return true;
}
例外タイプとは何ですか? –
エラーが指定されていません。 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) – FSouza
*決して*新しい例外をスローしないでください( "ユーザーの認証エラー" + ex.Message)。 **常に**新しい例外をスローする( "Error authenticating user。"、ex) '。そうすれば、ラップされた例外に関するスタックトレース情報が失われることはありません。 –