【问题标题】:Domain user automatic autentication for intranet内网域用户自动认证
【发布时间】:2011-06-21 08:42:11
【问题描述】:

我正在开发一个 Intranet 应用程序。该应用程序在 Windows Server 2008 上的 IIS 上运行。我正在使用 C# 对 ASP.NET 进行编码。

所以,我只想允许属于 OU ICT 成员的域用户。 我不需要登录表单,只需要自动身份验证。

Sql Server Reporting Services 就是这样工作的。用户无需登录,安全性基于AD。 -> 正是我正在寻找的。​​p>

我尝试了几种方法,例如使用 WidowsImpersonationContext 我在 OU 上遇到了死胡同。

如果有人可以帮助我,我将非常感激。

解决了我检查用户是否在组/ou中的部分。

但我无法在不登录的情况下从客户端机器获取 windows 用户。

你好,杰夫

【问题讨论】:

  • 仅仅检查用户是否在 OU 中不是很麻烦吗?
  • 我必须在 IIS 上使用什么身份验证?只有windows还是anonymous?
  • @Jeff,如果您可以将 OU 中的所有用户放入特定的 AD 组,那么您可以使用 windows 身份验证,然后使用WindowsPrincipal.IsInRole 方法进行访问控制。
  • @VinayC 感谢您的提示,如果我在我的 Visual Studio 上调试 IsInRole 但它在我的 IIS 上不起作用,那么它会抛出 System.InvalidOperationException:匿名身份无法执行模拟。在 WindowsImpersonationContext 上 wic = wi.Impersonate();
  • 如果不在登录表单中输入登录名和用户名,我如何让用户通过身份验证而不是匿名的..

标签: c# asp.net iis reporting-services


【解决方案1】:

我不确定这里的 OU 和组之间的混合,但也许以下内容会对您有所帮助:

参考 System.DirectoryServices.AccountManagement,

        var pc = new PrincipalContext(ContextType.Domain); 

        var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName,"DOMAIN\\USER");

        var g = System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(pc, IdentityType.DistinguishedName, "Everyone");

        var check = user.IsMemberOf(g);

HTH 多米尼克

【讨论】:

  • 我使用这段代码的那部分:WindowsPrincipal myPrincipal = new WindowsPrincipal((WindowsIdentity)HttpContext.Current.User.Identity); if (myPrincipal.IsInRole(@"domain\group")) { }
猜你喜欢
  • 2013-01-01
  • 1970-01-01
  • 2013-07-06
  • 2013-06-09
  • 2011-06-25
  • 2016-10-22
  • 2023-03-19
  • 2011-12-19
  • 2018-07-26
相关资源
最近更新 更多