域服务数据读写,有俩种模式
1、轻量级的数据读取
_domain是服务器的域名
获取连接PrincipalContext pc = new PrincipalContext(ContextType.Domain, _domain)
验证账号密码pc.ValidateCredentials(jobNumber, password)
引用System.DirectoryServices.AccountManagement命名空间后,按照如下如下方法,AD域验证
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, _domain))
{
// 工号一定要全
using (var userPrincipal = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName,loginModel.JobNumber))
{
if (userPrincipal == null)
{
return "账号不正确,请重新输入";
}
if (!pc.ValidateCredentials(loginModel.JobNumber, loginModel.Password))
{
return @"密码输入错误,请重新输入";
}
//GivenName是用户名称,Surname是工号(无前缀),Name是用户名称+工号(无前缀)
PersonDetailInfo personDetailInfo = new PersonDetailInfo()
{
SearchName = userPrincipal.Name,
UserName = userPrincipal.GivenName,
JobNumber = userPrincipal.SamAccountName,
EmailAddress = userPrincipal.EmailAddress
};
return personDetailInfo;
}
}
2、DectoryEntry
可以获取整个服务器的数据,也可以修改其中的信息
参考类似文章:
http://www.it165.net/pro/html/201308/6829.html作者:
唐宋元明清2188出处:
http://www.cnblogs.com/kybs0/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。