using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.DirectoryServices;
using System.Configuration;
namespace ADCheck
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
/// <summary>
/// 返回域的数组
/// </summary>
/// <returns>null</returns>
[WebMethod]
public string[] ImportDomain()
{
string[] ADName = null;
ArrayList ListView = new ArrayList();
DirectoryEntry MainGroup = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry domain in MainGroup.Children)
{
if (domain.Name != "WORKGROUP")
{
ListView.Add(domain.Name);//此代码获取局域网内的所有机器名
}
}
ADName = (string[])ListView.ToArray(typeof(string));
return ADName;
}
/// <summary>
/// 域验证方法
/// </summary>
/// <param name="Domain">域 tripodwx tripoddc之类</param>
/// <param name="UserName">用户名</param>
/// <param name="PassWord">密码</param>
/// <returns>false/ture</returns>
[WebMethod]
public bool Login(string Domain,string UserName,string PassWord)
{
string Msg;
try
{
Domain = "LDAP://" + Domain;
DirectoryEntry entry = new DirectoryEntry(Domain,UserName,PassWord);
DirectorySearcher search = new DirectorySearcher(entry);
SearchResult result = search.FindOne();
if (result == null)
{
return false;//错误的用户名或密码
}
else
{
return true;//登入成功
}
}
catch (Exception ex)
{
return false;//错误的用户名或密码
}
}
}
}
网友评论