如何列出Windows用户和组在ASP.NET? [英] How to list Windows users and groups in ASP.NET?
问题描述
我有一个ASP.NET网站项目,我需要列出所有的用户和他们的组在我的Windows系统。我已经设置了身份冒充为true,并在web.config中提供的管理员的用户名和密码。我从哪里开始?
I have a ASP.NET Website project and I need to list all the users and their groups on my Windows system. I have set the identity impersonation to true and provided the username and password of the admin in the web.config. Where do I start?
在此先感谢。
更新:
我有以下的code的时刻 -
I have the following code at the moment -
var machine = new DirectoryEntry("WinNT://<IP ADDRESS>");
foreach (DirectoryEntry child in machine.Children)
{
// get the child's group(s).
}
当我调试,我可以看到用户在machine.Children的列表。如何找到这个用户是属于什么?
When I debug, I can see the list of users in machine.Children. How do I find the group(s) that this user belongs to?
推荐答案
您可能要开始与的DirectoryEntry和.NET Active Directory支持。
You probably want to start with the DirectoryEntry and Active Directory support in .net.
下面是一个很好的资源: HTTP://www.$c$cproject .COM / KB /系统/ everythingInAD.aspx
Here's a good resource: http://www.codeproject.com/KB/system/everythingInAD.aspx
本地访问是相似的,即使你不是在一个域:
Local access is similar, even if you're not in a domain:
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" +
Environment.MachineName);
DirectoryEntry admGroup = localMachine.Children.Find("administrators",
"group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members) {
DirectoryEntry member = new DirectoryEntry(groupMember);
//...
}
这篇关于如何列出Windows用户和组在ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!