{"id":562,"date":"2012-03-05T09:07:10","date_gmt":"2012-03-05T08:07:10","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=562"},"modified":"2012-03-05T09:12:33","modified_gmt":"2012-03-05T08:12:33","slug":"c-net-ldap-zugriff","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=562","title":{"rendered":"C#.NET: LDAP Zugriff"},"content":{"rendered":"<h1>Aufgabenstellung<\/h1>\n<p>In gr\u00f6\u00dferen Firmen kann \u00fcber das LDAP-Protkoll auf Personendaten und -informationen zugegriffen werden. Die kann z.B. f\u00fcr eine Authentifizierung per Singlesignon genutzt werden. <\/p>\n<h1>Ansatz<\/h1>\n<p>M\u00f6chte man diesen Dienst nutzen, muss man zun\u00e4chst wissen auf welchem Server im Unternehmen ein solcher Dienst angeboten wird. Dies k\u00f6nnte z.B. ein Active Directory Server (Windows Server)  oder ein Lotus Notes Server (notesldap) sein. <\/p>\n<p>Zun\u00e4chst ben\u00f6tigt man den Import:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">using System.DirectoryServices;<\/pre>\n<h1>L\u00f6sung<\/h1>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nprivate void button1_Click(object sender, EventArgs e)\r\n{\r\n    DirectoryEntry DirEntry = new DirectoryEntry();\r\n    {\r\n        DirEntry.Path = &quot;LDAP:\/\/notesldap.it.company.com&quot;;\r\n        DirEntry.AuthenticationType = AuthenticationTypes.ServerBind;\r\n    }\r\n    Console.WriteLine(DirEntry.Name);\r\n\r\n    DirectorySearcher search = new DirectorySearcher(DirEntry);\r\n    {\r\n        \/\/ Tweak this to refine your search\r\n        search.Filter = &quot;(sn=Karpenstein)&quot;;\r\n        \/\/ I limit my results while I tweak          \r\n        search.SearchScope = SearchScope.Subtree;\r\n    }\r\n    try\r\n    {\r\n        foreach (SearchResult result in search.FindAll())\r\n        {\r\n            if (result != null)\r\n            {\r\n                DirectoryEntry de = result.GetDirectoryEntry();\r\n                textBox1.Text += &quot;====================================&quot;+br();\r\n                textBox1.Text +=\r\n                &quot;User: \\t\\t&quot; + de.Properties&#x5B;&quot;uid&quot;].Value.ToString() + br() +\r\n                &quot;objectclass:\\t\\t&quot; + de.Properties&#x5B;&quot;objectclass&quot;].Value.ToString();\r\n\r\n                IDictionaryEnumerator ide = de.Properties.GetEnumerator();\r\n                ide.Reset();\r\n\r\n                try\r\n                {\r\n                    while (ide.MoveNext())\r\n                    {\r\n                        PropertyValueCollection pvc = ide.Entry.Value as \r\n                                               PropertyValueCollection;\r\n\r\n                        textBox1.Text += ide.Entry.Key.ToString();\r\n                        textBox1.Text += pvc.Value;\r\n                    }\r\n                }\r\n                catch (Exception sdf)\r\n                {\r\n                    textBox1.Text += sdf.Message;\r\n                }\r\n                \r\n                \/\/textBox1.Text += &quot;location:\\t\\t&quot; + de.Properties&#x5B;&quot;location&quot;].\r\n                                              Value.ToString() + br();\r\n                \/\/textBox1.Text += &quot;maildomain:\\t\\t&quot; + de.Properties&#x5B;&quot;maildomain&quot;].\r\n                                              Value.ToString() + br();\r\n\r\n                textBox1.Text += &quot;sn:\\t\\t&quot; + de.Properties&#x5B;&quot;sn&quot;].\r\n                                            Value.ToString() + br();\r\n                \/\/textBox1.Text += &quot;dominocertificate:\\t\\t&quot; + \r\n                    de.Properties&#x5B;&quot;dominocertificate&quot;].\r\n                                             Value.ToString() + br();\r\n                textBox1.Text += &quot;mail:\\t\\t&quot; + de.Properties&#x5B;&quot;mail&quot;].\r\n                                             Value.ToString() + br();\r\n                textBox1.Text += &quot;l:\\t\\t&quot; + de.Properties&#x5B;&quot;l&quot;].\r\n                                            Value.ToString() + br();\r\n                textBox1.Text += &quot;displayname:\\t\\t&quot; + de.Properties&#x5B;&quot;displayname&quot;].\r\n                                            Value.ToString() + br();\r\n                textBox1.Text += &quot;givenname:\\t\\t&quot; + de.Properties&#x5B;&quot;givenname&quot;].\r\n                                           Value.ToString() + br();\r\n                \/\/textBox1.Text += &quot;dc:\\t\\t&quot; + de.Properties&#x5B;&quot;dc&quot;].\r\n                                           Value.ToString() + br();\r\n                \/\/textBox1.Text += &quot;dn:\\t\\t&quot; + de.Properties&#x5B;&quot;dn&quot;].\r\n                                           Value.ToString() + br();\r\n                textBox1.Text += &quot;cn:\\t\\t&quot; + de.Properties&#x5B;&quot;cn&quot;].\r\n                                            Value.ToString() + br();\r\n                textBox1.Text += &quot;====================================&quot;;\r\n            }\r\n        }\r\n    }\r\n    catch (Exception ex)\r\n    {\r\n        Console.WriteLine(ex.Message.ToString());\r\n    }\r\n    finally\r\n    {\r\n        search.Dispose();\r\n        DirEntry.Close();\r\n    }\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D562&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung In gr\u00f6\u00dferen Firmen kann \u00fcber das LDAP-Protkoll auf Personendaten und -informationen zugegriffen werden. Die kann z.B. f\u00fcr eine Authentifizierung per Singlesignon genutzt werden. Ansatz M\u00f6chte man diesen Dienst nutzen, muss man zun\u00e4chst wissen auf welchem Server im Unternehmen ein solcher Dienst angeboten wird. Dies k\u00f6nnte z.B. ein Active Directory Server (Windows Server) oder ein &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=562\" class=\"more-link\"><span class=\"screen-reader-text\">C#.NET: LDAP Zugriff<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,1,13],"tags":[],"class_list":["post-562","post","type-post","status-publish","format-standard","hentry","category-net","category-allgemein","category-windows-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-94","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=562"}],"version-history":[{"count":5,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/562\/revisions"}],"predecessor-version":[{"id":565,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/562\/revisions\/565"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}