如何使用 C# 从公司的域/网络设置中获取用户信息?

发布于 2024-10-12 08:52:48 字数 313 浏览 3 评论 0原文

有人告诉我,姓名、地址、电话等用户信息都存储在网络上(显然只有当一个人提供了这些信息时)。这是 Outlook 在网络上搜索用户时获取的信息(Outlook 填充联系人卡片的信息)。这显然是有效的,因为我可以搜索公司网络中的任何人,并且可以获得我们网络上世界各地的人员的结果。

我正在开发的程序是我们公司的内部程序,我的任务之一是用该信息预先填充表格。

我的问题是,我如何获得这些信息?它存储在哪里?我用什么对象来获取它?

编辑:我对此有点笼统。我真正需要的是当前用户的信息(“当前”是指登录到计算机并使用我的程序的用户)。获得它的最佳方式是什么?

I was told that user info like name, address, phone, etc are stored on the network (obviously only if a person has given that info). This is the info that Outlook gets when searching for users on the network (the info that Outlook populates the Contact card with). This obviously works because I can search for anyone in my company's network and I get results for people all over the world that are on our network.

The program I am working on is internal to our company and one of my tasks is to pre-populate a form with that info.

My question is, how do I get this information? Where is it stored? What object do I use to get it?

EDIT: I was a little general on this. What I really need is the current user's info ('current' being whoever is logged on to the computer and using my program). What is the best way to get it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黑白记忆 2024-10-19 08:52:49

要从 Active Directory 读取数据,您需要的类位于 System.DirectoryServices.dll 中。重要的是 DirectorySearcher 和 DirectoryEntry。查看另一个问题的前两个答案以获得更多代码: 如何在 C# 中获取当前用户的 Active Directory 详细信息

更新: 要获取当前用户的信息,请获取其登录名,然后在 Active 中进行搜索具有相同用户 ID 的用户的目录。像这样的东西:

adSearch.Filter = "(sAMAccountName=" + Environment.UserName + ")";

(在 ASP.Net 中,您可以在其他地方获取用户名。)

To read from Active Directory, the classes you need are in System.DirectoryServices.dll. The important ones are DirectorySearcher and DirectoryEntry. Take a look at the the first 2 answers to this other question to get more code: How to get the current user's Active Directory details in C#

Update: To get the current user's info, take their logon name and then do a search in Active Directory for a user with the same user ID. Something like this:

adSearch.Filter = "(sAMAccountName=" + Environment.UserName + ")";

(In ASP.Net you would get the user name elsewhere.)

分开我的手 2024-10-19 08:52:49

如果您使用的是 Active Directory,则可以根据给定的域和用户名从那里查询该信息。它基本上是一个 LDAP 存储,但网络上有大量关于如何实现它的信息。

这是另一个专门询问如何从 Active Directory 检索此信息的问题:

如何在 C# 中获取当前用户的 Active Directory 详细信息

在桌面应用中,要获取当前登录用户的 Windows 用户名,可以使用 Environment.UserName

If you're using Active Directory, then you can query that information from there, given the domain and username. It's basically an LDAP store, but there's tonnes of info on the web for how to implement it.

Here's another question that specifically asks how to retrieve this information from Active Directory:

How to get the current user's Active Directory details in C#

In a desktop app, to get the current logged-on user's Windows username, you can use Environment.UserName.

与往事干杯 2024-10-19 08:52:49

与 David 和 Neil Barnwell 提供的答案相配合的另一个提示是:

您可以使用 HttpContext.Current.User.Identity.Name 获取他们的 ID。

如果您想从程序集或其他后端代码中使用它,请确保添加 using System.Web

One additional tip to go along with the answers David and Neil Barnwell provided:

You can get their ID using HttpContext.Current.User.Identity.Name.

If you want use this from an assembly or some other back end code, make sure you add using System.Web.

給妳壹絲溫柔 2024-10-19 08:52:49

要回答“有没有办法获取当前域控制器...”的问题,对我有帮助的一种方法是使用 nltest 命令 [1],如下所示:

C:\>nltest /dsgetdc:yourdomain.com

它应该输出各种有用的东西。

[1] http://support.microsoft.com/kb/247811

To answer your question of "is there a way to get the current domain controller..." one way that has been helpful for me is to use the nltest command [1] like this:

C:\>nltest /dsgetdc:yourdomain.com

It should output all kinds of useful stuff.

[1] http://support.microsoft.com/kb/247811

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文