这个问题说明了一切。我们的应用程序目前正在根据数据库对用户进行身份验证。我们混合了内部和外部用户。对于新的内部应用程序,我们希望为内部用户移动到 AD,并且在未来我们希望建立一个允许外部用户在网站上注册的服务,但是注册码创建一个具有基于权限的 AD 用户在他们点击的 URL 上。我们的计划是 [customername].company.com。有哪些建议?你有过这样的经历吗?
编辑:这是 webforms 和 mvc 的混合体。 .NET 4.0
最佳答案
如果您使用的是 .NET 3.5 及更高版本,则应查看 System.DirectoryServices.AccountManagement
(S.DS.AM) 命名空间。在这里阅读所有相关信息:
Managing Directory Security Principals in the .NET Framework 3.5
基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// validate username/password credentials against AD
if (ctx.ValidateCredentials(userName, password))
{
// do something
}
// getting current user and testing against group membership
GroupPrincipal group = GroupPrincipal.FindByIdentity("YourGroup");
UserPrincipal user = UserPrincipal.Current;
if (user.IsMemberOf(group))
{
// do something
}
新的 S.DS.AM 使得在 AD 中与用户和组一起玩变得非常容易:
如果您主要使用 ASP.NET 应用程序,我建议检查 ASP.NET 成员资格和角色提供程序,它们具有 AD 接口(interface),以便您可以使用 AD 组(以及用户在这些组中的成员资格)作为允许/禁止某些功能的标准。
查看有关该主题的一些博客文章:
关于c# - 从本土表单例份验证转移到 AD 的策略是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5919795/