首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

对于ASP。NET AD编成!懂得帮帮 !不了解 的吼一下!有分

2011-12-26 
关于ASP。NET AD编成!懂得帮帮 !不了解 的吼一下!有分!要关于用代码操作AD的代码学校资料!!!如:怎么创建用

关于ASP。NET AD编成!懂得帮帮 !不了解 的吼一下!有分!
要关于   用代码操作   AD的代码   学校资料!!!如:   怎么创建用户   。怎么把用户添加组。怎么设置密码!!   怎么删除组!〉。。   写信   ~! up  也有分!!

[解决办法]
看MSDN
很详细的

UP~

==================================
小小姑娘
清早起床
提着裤子上茅房
茅房有人,不能再等
只好拉在裤子上..................
==================================
[解决办法]
System.DirectoryServices 命名空间有你需要的东西
[解决办法]
AD是什么东西来……
[解决办法]
ActiveDirectory
微软那套目录控制系统
其实是控制用户的
Windows Server 域用户才会用
[解决办法]
AD是什么D?
[解决办法]
o
说明白嘛,老是些莫明其妙的缩写
不会,压根没用过
[解决办法]
不懂 帮顶
[解决办法]
吼一下,真没这方面的资料。
[解决办法]
吼!!!!!!!!!!!!!
个卵
[解决办法]
<%@ Page language= "c# " AutoEventWireup= "true " %>
<%@ Import Namespace= "System.Threading " %>
<%@ Import Namespace= "System.Security.Principal " %>
<HTML>
<HEAD>
<title> WhoAmI </title>
</HEAD>
<body>
<form id= "WhoAmI " method= "post " runat= "server ">
<TABLE id=contextTable border=1>
<TR>
<TD align=middle colSpan=3 rowSpan= " ">
HttpContext.Current.User.Identity </TD>
</TR>
<TR>
<TD> <b> Name </b> </TD>
<TD> <asp:Label ID= "contextName " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> IsAuthenticated </b> </TD>
<TD> <asp:Label ID= "contextIsAuth " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> AuthenticationType </b> </TD>
<TD> <asp:Label ID= "contextAuthType " Runat=server /> </TD>
</TR>
</TABLE>
<br> <br>

<TABLE id=windowsIdentityTable border=1>
<TR>
<TD align=middle colSpan=3 rowSpan= " "> WindowsIdentity.GetCurrent() </TD>
</TR>
<TR>
<TD> <b> Name </b> </TD>
<TD> <asp:Label ID= "windowsName " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> IsAuthenticated </b> </TD>
<TD> <asp:Label ID= "windowsIsAuth " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> AuthenticationType </b> </TD>
<TD> <asp:Label ID= "windowsAuthType " Runat=server /> </TD>


</TR>
</TABLE>
<br> <br>

<TABLE id=threadIdentityTable border=1>
<TR>
<TD align=middle colSpan=3
rowSpan= " "> Thread.CurrentPrincipal.Identity </TD>
</TR>
<TR>
<TD> <b> Name </b> </TD>
<TD> <asp:Label ID= "threadName " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> IsAuthenticated </b> </TD>
<TD> <asp:Label ID= "threadIsAuthenticated " Runat=server /> </TD>
</TR>
<TR>
<TD> <b> AuthenticationType </b> </TD>
<TD> <asp:Label ID= "threadAuthenticationType " Runat=server /> </TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
<script runat=server>
void Page_Load(Object sender, EventArgs e)
{
IIdentity id = HttpContext.Current.User.Identity;
if(null != id)
{
contextName.Text = id.Name;
contextIsAuth.Text = id.IsAuthenticated.ToString();
contextAuthType.Text = id.AuthenticationType;
}
id = Thread.CurrentPrincipal.Identity;
if(null != id)
{
threadName.Text = id.Name;
threadIsAuthenticated.Text = id.IsAuthenticated.ToString();
threadAuthenticationType.Text = id.AuthenticationType;
}
id = WindowsIdentity.GetCurrent();
windowsName.Text = id.Name;
windowsIsAuth.Text = id.IsAuthenticated.ToString();
windowsAuthType.Text = id.AuthenticationType;
}
</script>
上面这段是获取域的用户名
[解决办法]
关注一下吧
[解决办法]
关注一下吧

[解决办法]
不了解 的吼一下!接分!
[解决办法]
佛门
[解决办法]
狮子吼
[解决办法]
可有分?
[解决办法]
/// <summary>
/// Active Directory的用户验证
/// </summary>
/// <param name= "username "> 用户 </param>
/// <param name= "pwd "> 密码 </param>
/// <param name= "domain "> 域名 </param>
/// <returns> </returns>
public bool IsAuthenticated(string username, string pwd, string domain)
{
string ADPath = "LDAP:// " + domain;
DirectoryEntry entry = new DirectoryEntry(ADPath,
username, pwd);

try
{
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;


}
//string str = result.GetDirectoryEntry().Properties[ "displayName "].Value.ToString();

return true;
}
catch (Exception ex)
{
AppException oAppException = new AppException( "AD Services Login ", ex);
return false;
}
}


/// <summary>
/// 读取AD用户信息
/// </summary>
/// <param name= "ADUsername "> 用户 </param>
/// <param name= "ADPassword "> 密码 </param>
/// <param name= "domain "> 域名 </param>
/// <returns> </returns>
public static SortedList AdUserInfo(string ADUsername, string ADPassword, string domain ,Label lb)
{
DirectorySearcher src;
string ADPath = "LDAP:// " + domain;// "ou=总公司,DC=abc,DC=com,DC=cn "; + ",ou=总公司 "
SortedList sl = new SortedList();
string GroupName = string.Empty;
GroupName = "总公司 ";
DirectoryEntry de = new DirectoryEntry(ADPath, ADUsername, ADPassword);
string domainFilter=ConfigurationManager.AppSettings[ "DomainFilter "].ToString();
if (domainFilter != string.Empty || domainFilter != " ")
{
domainFilter = domainFilter.Replace( "_ ", "& "); //( "(&(objectCategory=person)(objectClass=user)) ");
src = new DirectorySearcher(domainFilter);
}
else
{
src = new DirectorySearcher();
}
src.SearchRoot = de;
src.PageSize = 10000;// 此参数可以任意设置,但不能不设置,如不设置读取AD数据为0~999条数据,设置后可以读取大于1000条数据。
// src.SizeLimit = 2000;
src.SearchScope = SearchScope.Subtree;
try
{
foreach (SearchResult res in src.FindAll()) // foreach (SearchResult res in src.FindAll()) foreach (DirectoryEntry res in de.Children)
{
//if (res.GetDirectoryEntry().Properties[ "EmailAddress "].Value != " ")
//{
sl.Add(res.GetDirectoryEntry().Properties[ "Name "].Value, res.GetDirectoryEntry().InvokeGet( "Description "));
// }
}
}
catch (Exception ex)
{
AppException oAppException = new AppException( "Get Ad Info ", ex);
lb.Text = ex.Message;
}
return sl;
}

[解决办法]
引用 System.DirectoryServices.dll
System.EnterpriseServices.dll
[解决办法]
那不就等于不要银行卡密码,把钱取出来
。。。
总得分配一个权限吧
[解决办法]
up
[解决办法]
mark
[解决办法]
没这方面的应用,KK
[解决办法]
up
[解决办法]
没用过
[解决办法]
吼一下
[解决办法]
public bool IsAuthenticated(string username, string pwd, string domain)


{
string ADPath = "LDAP:// " + domain;
DirectoryEntry entry = new DirectoryEntry(ADPath,
username, pwd);

try
{
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;
}
//string str = result.GetDirectoryEntry().Properties[ "displayName "].Value.ToString();

return true;
}
catch (Exception ex)
{
AppException oAppException = new AppException( "AD Services Login ", ex);
return false;
}
}


/// <summary>
/// 读取AD用户信息
/// </summary>
/// <param name= "ADUsername "> 用户 </param>
/// <param name= "ADPassword "> 密码 </param>
/// <param name= "domain "> 域名 </param>
/// <returns> </returns>
public static SortedList AdUserInfo(string ADUsername, string ADPassword, string domain ,Label lb)
{
DirectorySearcher src;
string ADPath = "LDAP:// " + domain;// "ou=总公司,DC=abc,DC=com,DC=cn "; + ",ou=总公司 "
SortedList sl = new SortedList();
string GroupName = string.Empty;
GroupName = "总公司 ";
DirectoryEntry de = new DirectoryEntry(ADPath, ADUsername, ADPassword);
string domainFilter=ConfigurationManager.AppSettings[ "DomainFilter "].ToString();
if (domainFilter != string.Empty || domainFilter != " ")
{
domainFilter = domainFilter.Replace( "_ ", "& "); //( "(&(objectCategory=person)(objectClass=user)) ");
src = new DirectorySearcher(domainFilter);
}
else
{
src = new DirectorySearcher();
}
src.SearchRoot = de;
src.PageSize = 10000;// 此参数可以任意设置,但不能不设置,如不设置读取AD数据为0~999条数据,设置后可以读取大于1000条数据。
// src.SizeLimit = 2000;
src.SearchScope = SearchScope.Subtree;
try
{
foreach (SearchResult res in src.FindAll()) // foreach (SearchResult res in src.FindAll()) foreach (DirectoryEntry res in de.Children)
{
//if (res.GetDirectoryEntry().Properties[ "EmailAddress "].Value != " ")
//{
sl.Add(res.GetDirectoryEntry().Properties[ "Name "].Value, res.GetDirectoryEntry().InvokeGet( "Description "));
// }
}
}
catch (Exception ex)
{
AppException oAppException = new AppException( "Get Ad Info ", ex);
lb.Text = ex.Message;
}
return sl;
}

热点排行