如何使用 c# 循环访问文件和活动目录权限?



我是一名程序员学生,我需要制作一个 Web 应用程序,允许查看所有文件夹、子文件夹和文件以及谁可以访问它们......我还需要列出活动目录的组和用户,并遍历所有服务器以修改它们。 但我是一个 c# 菜鸟,我 asp.net 3 周前开始学习...... 我想知道是否有人可以通过解释所有 MVC 层之间的通信来帮助我。 我已经编写了一些函数,但我不知道如何让它们交互...... 感谢您的帮助!(对不起,我的英语不好,我是法国人... ^^')

对于新手来说,您要问的内容确实很复杂。 由于您正在开始并且正在使用 asp.net 我建议您重新开始 ASP.NET Core,这是基于.NetCore构建的新Web框架。

那里有很多资源和课程。我建议您订阅Pluralsight,有很多课程,它们真的很棒,几乎所有的老师都是 MVP。有一条路径(有点像carreer)用于构建 ASP.NET 核心应用程序:

我已经在 .net core 中与活动目录组和用户合作过一些,但您需要首先了解基础知识。

以下代码包含一些我用来验证用户使用活动目录的方法,并获取目录中所有计算机的列表,但正如我所说,您需要首先了解基础知识,以使该代码在您的应用程序中正常工作

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个月的免费pluralsight订阅。

最新更新