惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
Project Zero
Project Zero
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Vercel News
Vercel News
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
The Hacker News
The Hacker News
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Scott Helme
Scott Helme
T
Threatpost
爱范儿
爱范儿
N
Netflix TechBlog - Medium
D
Docker
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
K
Kaspersky official blog
H
Help Net Security
S
Secure Thoughts
T
Threat Research - Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
G
Google Developers Blog
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
B
Blog
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Simon Willison's Weblog
Simon Willison's Weblog
S
Securelist
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog

博客园 - pot

在框架中(IFRAME/FRAMESET)传递COOKIE的解决方案[转] jQuery图片播放插件Fancybox使用方法 C#生成缩略图代码 数据抓取的一个类,包含一些常用的方法 抓取AJAX网页的方法-Firefox组件,C#集成 C#编号的ActiveX控件采用CAB的布署方式实例 C#编写ActiveX控件实例(包括命令和事件) PdfAcroViewer 用XML反序列化快速完成ASP.NET配置文件 - pot - 博客园 android Activity类的使用 Android中的Intent详细讲解 Android模拟器常用使用,和基本功能使用 ZPL II 命令参考 正则表达式语法 - pot - 博客园 《C#异常处理》 C#中接口的作用 The RSA key container could not be opened - pot ASP.NET 页面事件执行顺序 关于object sender,EventArgs e 的一些解释
C#代码登录活动目录
pot · 2010-07-23 · via 博客园 - pot

代码

using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;namespace ChangeControlApp
{
    
class LdapAuthentication
    {
        
private String _path;
        
private String _filterAttribute;public LdapAuthentication(String path)
        {
            _path 
= path;
        }
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.            
                Object obj = entry.NativeObject;

                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;
        }
public String GetGroups()
        {
            DirectorySearcher search 
= new DirectorySearcher(_path);
            search.Filter 
= "(cn=" + _filterAttribute + ")";
            search.PropertiesToLoad.Add(
"memberOf");
            StringBuilder groupNames 
= new StringBuilder();try
            {
                SearchResult result 
= search.FindOne();int propertyCount = result.Properties["memberOf"].Count;

                String dn;

int equalsIndex, commaIndex;for (int propertyCounter = 0; propertyCounter < propertyCount; propertyCounter++)
                {
                    dn 
= (String)result.Properties["memberOf"][propertyCounter];

                    equalsIndex 

= dn.IndexOf("="1);
                    commaIndex 
= dn.IndexOf(","1);
                    
if (-1 == equalsIndex)
                    {
                        
return null;
                    }

                    groupNames.Append(dn.Substring((equalsIndex 

+ 1), (commaIndex - equalsIndex) - 1));
                    groupNames.Append(
"|");

                }
            }

catch (Exception ex)
            {
                
throw new Exception("Error obtaining group names. " + ex.Message);
            }
            
return groupNames.ToString();
        }

    }
}

ad path 传值类似:LDAP://Asia2.ccb2.com