知道域用户名如何确认计算机名,如何获得域用户的用户名

谢谢!

已经解决,默认IIS配置既可以。下面是代码(供和我一样的菜鸟参考):

C#

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.DirectoryServices;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string principal = System.Environment.UserName;

string filter = string.Format("(sAMAccountName={0})", principal );

string domain = "YourDoMainName";

string[] properties = new string[] { "fullname" };

DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure);

DirectorySearcher searcher = new DirectorySearcher(adRoot);

searcher.SearchScope = SearchScope.Subtree; searcher.ReferralChasing = ReferralChasingOption.All;

searcher.PropertiesToLoad.AddRange(properties);

searcher.Filter = filter;

SearchResult result = searcher.FindOne();

DirectoryEntry directoryEntry = result.GetDirectoryEntry();

Label1.Text = "用户姓名:" + directoryEntry.Properties["displayName"][0].ToString();

}

}

VB.Net

Imports System.Collections

Imports System.DirectoryServices

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim principal As String = System.Environment.UserName

Dim filter As String = String.Format("(sAMAccountName={0})", principal)

Dim domain As String = "YourDoMainName"

Dim properties As String() = New String() {"fullname"}

Dim adRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & domain, Nothing, Nothing, AuthenticationTypes.Secure)

Dim searcher As DirectorySearcher = New DirectorySearcher(adRoot)

searcher.SearchScope = SearchScope.Subtree

searcher.ReferralChasing = ReferralChasingOption.All

searcher.PropertiesToLoad.AddRange(properties)

searcher.Filter = filter

Dim result As SearchResult = searcher.FindOne()

Dim directoryEntry As DirectoryEntry = result.GetDirectoryEntry()

Label1.Text = "用户姓名:" + directoryEntry.Properties("displayname")(0).ToString

End Sub

End Class

环境:VS2005

注:需要添加引用System.DirectoryServices

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值