当前位置: 代码迷 >> ASP.NET >> 访问AD有关问题:asp.net怎么访问Active Directory获取域用户
  详细解决方案

访问AD有关问题:asp.net怎么访问Active Directory获取域用户

热度:7991   发布时间:2013-02-25 00:00:00.0
访问AD问题:asp.net如何访问Active Directory获取域用户?


AD(域控制器)在服务器A上,AP(web系统)在服务器B上,
域名称:dnssvr;

在局域网内的机器都加入域dnssvr,然后访问服务器B上的AP

请问在AP的首页该如何写代码获取访问此AP的用户并去AD验证?

谢谢各位先!

------解决方案--------------------------------------------------------
<%@ 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;
  相关解决方案