gpt4 book ai didi

asp.net - 如何从 Web 应用程序中的客户端计算机获取 AD 凭据?

转载 作者:行者123 更新时间:2023-12-01 15:03:16 24 4
gpt4 key购买 nike

是否可以从 Web 应用程序中为客户端计算机上的用户获取 activedirectory 凭据?

澄清一下,我正在设计一个 Web 应用程序,该应用程序将托管在客户的内部网上。

要求应用程序的用户在访问应用程序时不会被提示输入凭据,而是应自动获取登录到客户端计算机的用户的凭据,而无需用户交互。

最佳答案

当然。这对于 Intranet 应用程序特别有用。

由于您没有指定您的环境,我假设它是 .NET,但这当然不是唯一可能的方法。

可以使用 LDAP 轻松查询 Active Directory .如果您使用的是 .NET,则可以执行类似 this code example 中的操作或者我下面的例子。您也可以在 SQL environments 内完成

如果您只需要 Windows 来处理身份验证,您可以为 Windows Authentication 设置一个 .NET Web 应用程序等。 .务必turn off Anonymous Logins在您的应用程序的 IIS 中。完成后,您将能够访问用户的 Windows 登录名并使用它进行进一步的安全检查(例如,他们在 AD 中的 group/role membership)。

您还可以使用像 Enterprise Library 的 Security Application Block 这样的东西来简化整个困惑局面。 .


这是一个简短的 C# 示例:(转换为 VB.NET here)

using System.DirectoryServices;

/// <summary>
/// Gets the email address, if defined, of a user from Active Directory.
/// </summary>
/// <param name="userid">The userid of the user in question. Make
/// sure the domain has been stripped first!</param>
/// <returns>A string containing the user's email address, or null
/// if one was not defined or found.</returns>
public static string GetEmail(string userid)
{
DirectorySearcher searcher;
SearchResult result;
string email;

// Check first if there is a slash in the userid
// If there is, domain has not been stripped
if (!userid.Contains("\\"))
{
searcher = new DirectorySearcher();
searcher.Filter = String.Format("(SAMAccountName={0})", userid);
searcher.PropertiesToLoad.Add("mail");
result = searcher.FindOne();
if (result != null)
{
email = result.Properties["mail"][0].ToString();
}
}

return email;
}

您不必指定域 Controller 。为 DirectorySearcher 执行空/默认构造函数将导致它尝试自动查找一个 — 事实上,这是 the preferred method .

关于asp.net - 如何从 Web 应用程序中的客户端计算机获取 AD 凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/192366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com