使用 C# 从 ASP.Net MVC 访问 Active Directory
- 作者: 彩色哥爱彩姐
- 来源: 51数据库
- 2022-10-21
问题描述
我需要访问 Active Directory 以获取有关客户所属组的信息.我的项目是一个使用 C# 的 ASP.Net MVC 应用程序.我以前从未针对 Active Directory 进行过编程,因此需要一些关于最佳入门方法、用于访问信息的安全模型的建议,并且可能会为我提供一些不错的教程.
I need to access Active Directory to get information about groups that customers belong to. The project I have is an ASP.Net MVC application using C#. I've never programmed against Active Directory before, and need some advice on what the best way to get started is, what security model to use to access the information, and maybe point me to some good tutorials.
推荐答案
由于您使用的是 MVC,您可以访问新的 System.DirectoryServices.AccountManagement .NET 3.5 中的命名空间.这些类应该优先于 DirectoryServices 本身中的旧类,因为它们使用起来要简单得多.有几个问题在 3.5 中尚未解决(例如,查询组时限制 1500 个成员),但我确信这些问题已在 .NET 4.0 中得到修复.对于大多数任务,新类都能很好地工作.
Since you're using MVC, you have access to the new System.DirectoryServices.AccountManagement namespace in .NET 3.5. These classes should be preferred over the older classes in DirectoryServices itself as they are much simpler to use. There are a couple of gotchas that haven't been solved in 3.5 (1500 member limit when querying groups, for instance), but I'm assured that these have been fixed in .NET 4.0. For most tasks, the new classes work very well.
using (var context = new PrincipalContext( ContextType.Domain ))
{
using (var user = UserPrincipal.FindByIdentity( context, "username" ))
{
var groups = user.GetAuthorizationGroups();
...
}
}
- 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 包还原找不到包,没有源
