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

System.DirectoryServices - 服務(wù)器無法運行

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

問題描述

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

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

奇怪的事情:

  • 僅在用戶尚未保存到數(shù)據(jù)庫中時發(fā)生(新的未知用戶)
  • 僅在實時系統(tǒng)上出現(xiàn),在本地開發(fā)環(huán)境中一切正常

這是我在日志郵件中收到的內(nèi)容:

This is what I get in a logging mail:

來源:System.DirectoryServices

Source : System.DirectoryServices

消息:服務(wù)器無法運行.

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)

這就是我實現(xiàn) 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.

推薦答案

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

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.

要了解您的默認(rèn) 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 服務(wù)器的綁定字符串.

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

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

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!

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

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

相關(guān)文檔推薦

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 枚舉組時發(fā)生錯誤 (1301).升級到 Server 2012 域控制
Using PrincipalSearcher to find users with quot;orquot; parameters(使用 PrincipalSearcher 查找?guī)в小盎虻挠脩魠?shù))
Get members of an Active Directory group recursively, i.e. including subgroups(遞歸獲取 Active Directory 組的成員,即包括子組)
主站蜘蛛池模板: 黄色小视频在线免费观看 | 亚洲 欧美 另类 综合 偷拍 | 国产一区二区在线观看视频 | 黄色欧美视频 | 国产精品美女久久久久av爽 | 天天爱夜夜操 | 国产在线小视频 | 日韩精品久久久久久久酒店 | 久久综合五月天 | 亚洲黄色av | 五月婷综合| 毛片毛片毛片 | 午夜爽爽影院 | 国产又粗又猛又黄又爽无遮挡 | 美日韩一区二区三区 | 可以免费看的av | 久久综合99 | 免费在线小视频 | 亚洲激情中文字幕 | 免费在线成人网 | 久久久精品免费 | a毛片视频 | 四川一级毛毛片 | 国产日韩一区 | 久久av资源 | 黄色在线免费网站 | 久久久午夜精品 | 日本黄色录像 | 国产成人精品毛片 | 国产视频黄 | www视频在线观看 | 日本一本视频 | 日日干夜夜撸 | 久久精品99久久久久久 | 91成年人 | 欧美xxx视频| 欧美性生交xxxxx久久久 | 日韩精品一级毛片在线播放 | 婷婷久久五月天 | 国产色自拍 | 欧美综合视频 |