c# - 如何使用 c# 遍历文件和活动目录权限?
问题描述
我是一名程序员学生,我需要制作一个 Web 应用程序,允许查看所有文件夹、子文件夹和文件以及谁可以访问它们...我还需要列出活动目录的组和用户并遍历所有服务器以修改它们。但我是 ac# 菜鸟,我在 3 周前开始学习 asp.net ......我想知道是否有人可以通过解释所有 MVC 层之间的通信方式来帮助我。我已经编写了一些函数,但我不知道如何让它们交互...感谢您的帮助!(对不起我的英语不好,我是法国人...... ^^')
解决方案
对于新手来说,您要问的问题确实很复杂。由于您刚开始并且正在使用 asp.net,我建议您从ASP.NET Core重新开始,它是构建在 .Net Core 之上的新 Web 框架。
那里有很多资源和课程。我建议你订阅 Pluralsight,有很多课程,而且真的很棒,几乎所有的老师都是 MVP。构建 ASP.NET Core 应用程序有一条路径(有点像职业生涯):.
我在 .net 核心中使用过一些活动目录组和用户,但您需要先了解最基本的知识。
以下代码包含我用来验证活动目录用户的一些方法,以及获取目录中所有计算机的列表,但正如我所说,您需要先了解基础知识才能做到这一点代码在您的应用程序中正常工作
public bool ValidateWithActiveDirectory(string domainUrl, string userName, string password) {
using (var context = new PrincipalContext(ContextType.Domain, domainUrl)) {
UserPrincipal UserPrincipal1 = new UserPrincipal(context);
PrincipalSearcher search = new PrincipalSearcher(UserPrincipal1);
foreach (UserPrincipal result in search.FindAll()) {
}
if (context.ValidateCredentials(userName, password)) {
return true;
}
}
return false;
}
public IEnumerable<Computer> GetActiveDirectoryComputers(string domainUrl) {
IList<Computer> computers = new List<Computer>();
PrincipalContext context = new PrincipalContext(ContextType.Domain, domainUrl);
ComputerPrincipal computerPrincipal = new ComputerPrincipal(context);
PrincipalSearcher search = new PrincipalSearcher(computerPrincipal);
foreach (ComputerPrincipal result in search.FindAll()) {
computers.Add(new Computer(result.Name));
}
return computers;
}
注意:如果您加入Visual Studio Dev Essentials,他们将为您提供 1 个月的免费复数视力订阅。
推荐阅读
- kubernetes - Kubernetes - 所有 Pod 的共享环境变量
- winapi - 虚拟流文件,如同步客户端
- cmake - CTest 在子目录中添加测试
- java - 使用 ResponseBuilder 强制位置标头中的相对 URI
- cucumber - 如何轮询特定时间间隔的请求并确定通过或失败
- git - 在 git 存储库中,如何仅创建读取访问权限的用户?
- c# - WebApplicationFactory 在启动时设置 IP 地址
- javascript - 如何从仅出现在 console.log() 中而不出现在 JSON.stringify() 中的 JavaScript 对象中获取属性?
- python - 将数据框转换为python中的列表列表
- json - 反应如何在正确的位置更新 json?