0

プリンシパル コンテキストを使用して Active Directory に接続しようとしています。私は以下のコードで試しました。

using (var context = new PrincipalContext(ContextType.Domain,
                        ConfigurationManager.AppSettings["DomainName"].ToString()))
                    {
                        try
                        {
                            writeLog("Before:" + isCheckUserName);
                            writeLog("Context name:" + context.Name);
                            var user = UserPrincipal.FindByIdentity(context, GetCurrentWindowsLogin());

                            writeLog("GetCurrent:" + GetCurrentWindowsLogin());
                            writeLog("After:" + user.EmployeeId);
                            if (user != null) {
                                StaffName = user.DisplayName;
                                StaffID = user.EmployeeId;

                            }

                        }
                        catch (Exception ex)
                        {
                            writeLog($"Second try: Error - {ex.Message} Inner Exception: {ex.InnerException.Message}");
                        }
                    }

このコードはクライアントのローカル マシンでは問題なく動作しますが、クライアントのサーバーにアップロードすると null 参照例外がスローされます。

何か案が。ありがとう。

4

1 に答える 1