如何在 ASP.NET 中列出 Windows 用户和组?
- 作者: 开心就好32777468
- 来源: 51数据库
- 2022-10-21
问题描述
我有一个 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 ***** in the web.config. Where do I start?
提前致谢.
更新:
我现在有以下代码 -
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?
推荐答案
您可能希望从 .net 中的 DirectoryEntry 和 Active Directory 支持开始.
You probably want to start with the DirectoryEntry and Active Directory support in .net.
这里有一个很好的资源:http://www.codeproject.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("*****istrators",
"group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members) {
DirectoryEntry member = new DirectoryEntry(groupMember);
//...
}
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
