我编写了以下代码,以确定用户登录是否在活动目录中有一个帐户,因此我可以允许他继续并且它正常工作:
public bool AuthenticateUser(string domain, string username, string password, string LdapPath)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
并且效果很好,唯一的问题是我需要使用xamarin表单制作相同的东西,我怎么可能?
答案 0 :(得分:0)
DirectorySearcher是一个可以从服务器API /代码中使用的类。
我建议您创建一个Web API,它将执行相同的工作,并且将由您的Xamarin应用程序调用。