简体   繁体   English

.Net目录服务用于本地身份验证

[英].Net Directory services for local authentication

I am using directory services in .Net for first time.I want to use it to authenticate against local users on my machine in an asp.net website application The code is as follows 我是第一次使用.Net中的目录服务。我想使用它在asp.net网站应用程序中针对我的计算机上的本地用户进行身份验证。代码如下

DirectoryEntry entry = new DirectoryEntry("WinNT://"+Environment.MachineName+"/administrator", txtBoxUserName.Text, txtBoxPWD.Text);

For some reason I get an exception of "System.Runtime.InteropServices.COMException" although I used the right user name and password for administrator user. 由于某种原因,尽管我为管理员用户使用了正确的用户名和密码,但是却出现了“ System.Runtime.InteropServices.COMException”异常。

Any Help would be appreciated 任何帮助,将不胜感激

Try this: 尝试这个:


public bool IsAuthenticationValid(string userName, string password)
{
    using (var context = new PrincipalContext(ContextType.Machine))
    {
        return context.ValidateCredentials(userName, password);
    }
}

Edit: Forgot to mention you will need System.DirectoryServices and System.DirectoryServices.AccountManagement references. 编辑:忘记提及您将需要System.DirectoryServices和System.DirectoryServices.AccountManagement引用。

If you hit the same error, please describe what environment you are running this code in. By that I mean command line, web app, etc. Just some more background to see if I can help you further. 如果您遇到相同的错误,请描述运行此代码的环境。我的意思是命令行,Web应用程序等。仅提供一些背景知识,看看我是否可以进一步为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有本地活动目录的.Net Core身份验证 - .Net Core Authentication with local active directory 现有Asp.Net核心应用程序中缺少与Azure Active Directory连接的服务的身份验证 - Authentication with Azure Active Directory connected services missing in existing Asp.Net core application 使用服务帐户的Active Directory身份验证 - Active Directory Authentication using services account 列出所有使用目录服务的本地用户 - list all local users using directory services ASP.NET 目录身份验证 - ASP.NET Directory Authentication .Net的目录服务引发了一个奇怪的例外 - .Net's Directory Services throws a strange exception 如何在源代码中使用加密密码进行Directory Services身份验证 - How to use encrypted password in source code for Directory Services authentication 无法使用 Azure Active Directory 连接到连接服务身份验证 - Can't connect to Connected Services Authentication with Azure Active Directory 使用WCF RIA服务在非本地服务器上进行身份验证(Silverlight 4) - Authentication on non-local server with WCF RIA services (Silverlight 4) .NET OWIN身份验证 - Cookie + Windows(活动目录) - .NET OWIN Authentication - Cookie + Windows (active directory)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM