问题描述
我需要访问 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# 从 ASP.Net MVC 访问 Active Directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)