久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

System.DirectoryServices - 服務器無法運行

System.DirectoryServices - The server is not operational(System.DirectoryServices - 服務器無法運行)
本文介紹了System.DirectoryServices - 服務器無法運行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在使用 Windows 身份驗證的網站上收到錯誤消息.

I get an error by a website, on which I use Windows Authentication.

奇怪的事情:

  • 僅在用戶尚未保存到數據庫中時發生(新的未知用戶)
  • 僅在實時系統上出現,在本地開發環境中一切正常

這是我在日志郵件中收到的內容:

This is what I get in a logging mail:

來源:System.DirectoryServices

Source : System.DirectoryServices

消息:服務器無法運行.

Message: The server is not operational.

跟蹤:
在 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
在 System.DirectoryServices.DirectoryEntry.Bind()
在 System.DirectoryServices.DirectoryEntry.get_AdsObject()
在 System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
在 System.DirectoryServices.DirectorySearcher.FindOne()
在 Smarthouse.Labs.DataAccess.UserListManager.SaveUser(String windowsUserName)

Trace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
at Smarthouse.Labs.DataAccess.UserListManager.SaveUser(String windowsUserName)

這就是我實現 DirectorySearch 的方式:

This is how I implement DirectorySearch:

private void SaveUser(string windowsUserName)
{
    string[] domainAndUser = windowsUserName.Split('\');
    string domain = domainAndUser[0];
    string username = domainAndUser[1];

    DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
    DirectorySearcher search = new DirectorySearcher(entry);

    try
    {
        // Bind to the native AdsObject to force authentication.
        search.Filter = "(SAMAccountName=" + username + ")";
        search.PropertiesToLoad.Add("cn");
        search.PropertiesToLoad.Add("sn");
        search.PropertiesToLoad.Add("givenName");
        search.PropertiesToLoad.Add("mail");

        SearchResult result = search.FindOne();

        if (result == null)
        {
            throw new Exception("No results found in Windows authentication.");
        }

        User userToSave = new User();
        userToSave.FirstName = (String) result.Properties["givenName"][0];
        userToSave.LastName = (String) result.Properties["sn"][0];
        userToSave.Email = (String) result.Properties["mail"][0];
        userToSave.Username = windowsUserName;
        userToSave.Guid = Guid.NewGuid();

        SaveUser(userToSave);
    }
    catch (Exception ex)
    {
        throw new Exception("Error authenticating user. " + ex.Message, ex);
    }
    finally
    {
        //Dispose service and search to prevent leek in memory
        entry.Dispose();
        search.Dispose();
    }
}

如果需要更多代碼示例,請告訴我.

If more code examples are needed just tell me.

推薦答案

您的問題是您正在使用普通"域名進行綁定 - 這在 LDAP 中不起作用.實際上,如果您嘗試綁定到 LDAP://MyDomain,您真正所做的是嘗試綁定到名為 服務器代碼>我的域.

Your problem is that you're using a "plain" domain name to bind - this won't work in LDAP. Actually, if you try to bind to LDAP://MyDomain, what you're really doing is trying to bind to the server called MyDomain.

您需要一個有效的 LDAP 綁定字符串 - 類似于 LDAP://dc=yourdomain,dc=local 之類的東西.

You need a valid LDAP bind string - something like LDAP://dc=yourdomain,dc=local or something.

要了解您的默認 LDAP 綁定上下文是什么,請使用以下代碼片段:

To find out what your default LDAP binding context is, use this code snippet:

DirectoryEntry deRoot = new DirectoryEntry("LDAP://RootDSE");

if (deRoot != null)
{
   string defaultNamingContext = deRoot.Properties["defaultNamingContext"].Value.ToString();
}

獲得該字符串后 - 將其用作 LDAP 服務器的綁定字符串.

Once you have that string - use that as your bind string to your LDAP server.

如果您使用 .NET 3.5 及更高版本,您應該查看 System.DirectoryServices.AccountManagement (S.DS.AM) 命名空間.在此處閱讀所有相關信息:

And if you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

  • 在 .NET Framework 3.5 中管理目錄安全主體
  • System.DirectoryServices.AccountManagement 上的 MSDN 文檔

基本上,您可以定義域上下文并輕松找到 AD 中的用戶和/或組:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context -- no domain name needed, uses default domain 
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username);

if(user != null)
{
   // do something here....     
}

新的 S.DS.AM 使在 AD 中與用戶和組一起玩變得非常容易!

The new S.DS.AM makes it really easy to play around with users and groups in AD!

這篇關于System.DirectoryServices - 服務器無法運行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Asp.net System.Web.HttpContext.Current.Session null in global.asax(Asp.net System.Web.HttpContext.Current.Session 在 global.asax 中為 null)
Caught exception is null itself !(捕獲的異常本身為空!)
Is an empty textbox considered an empty string or null?(空文本框被視為空字符串還是 null?)
UserPrincipals.GetAuthorizationGroups An error (1301) occurred while enumerating the groups. After upgrading to Server 2012 Domain Controller(UserPrincipals.GetAuthorizationGroups 枚舉組時發生錯誤 (1301).升級到 Server 2012 域控制
Using PrincipalSearcher to find users with quot;orquot; parameters(使用 PrincipalSearcher 查找帶有“或的用戶參數)
Get members of an Active Directory group recursively, i.e. including subgroups(遞歸獲取 Active Directory 組的成員,即包括子組)
主站蜘蛛池模板: 国产精品乱码一区二区三区 | 国产真实精品久久二三区 | 国产精品伦一区二区三级视频 | av日日操| 国产精品成人国产乱一区 | 国产精品久久久久久久岛一牛影视 | 91激情电影 | 亚洲系列第一页 | 久草视频网站 | 99国产精品久久久久 | 精品视频在线一区 | 欧日韩不卡在线视频 | 国产免费播放视频 | 欧美日韩午夜精品 | 先锋资源站 | 人人九九精 | 国产成人精品一区二区三区 | 日韩欧美不卡 | 成人妇女免费播放久久久 | 国产一区二区在线播放视频 | 一级一级毛片免费看 | 久久精品视频网站 | 精品国产乱码一区二区三 | 欧美成视频 | 国产欧美一区二区三区在线看 | 国产一区www | 日韩中文字幕在线视频 | 午夜免费看视频 | 国产精品视频久久 | 久久久一区二区三区 | 国产精品欧美一区喷水 | 欧美精品欧美精品系列 | 国产xxxx搡xxxxx搡麻豆 | 日韩伦理一区二区三区 | 国产免费观看久久黄av片涩av | 暖暖成人免费视频 | 久久99视频免费观看 | 国产午夜精品视频 | 久久亚洲天堂 | 午夜寂寞福利视频 | 日韩欧美一二三区 |