简体   繁体   English

对Active Directory进行ASP.NET用户身份验证时遇到问题

[英]Trouble Authenticating ASP.NET Users Against Active Directory

I replaced our domain name with "demo"... please ignore missing commas and such in the image below. 我用“演示”替换了我们的域名...请忽略下图中的逗号。

My question is as follows: 我的问题如下:

I want to authenticate the SBSUsers in my ASP.NET web application. 我想在我的ASP.NET Web应用程序中对SBSUsers进行身份验证。 I cannot figure out what my active directory path needs to be in order to get it to work... 我无法弄清楚我的活动目录路径需要什么才能使其正常工作...

When I set it as follows, it fails to authenticate (I assume because my users are not under that path)... but it doesn't give me an error: 当我进行如下设置时,它无法通过身份验证(我认为是因为我的用户不在该路径下)...但是它没有给我一个错误:

string adPath = "LDAP://ac-dc01.demo.local:389/CN=Configuration,DC=demo,DC=local";
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(adPath, domainAndUsername, pwd);
// 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;
}
// Update the new path to the user in the directory
adPath = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];

When I set it to what I think it should be, it errors on the entry.NativeObject line. 当我将其设置为我认为应该的值时,会在entry.NativeObject行上出错。

string adPath = "ldap://ac-dc01.demo.local:389/OU=SBSUsers,OU=Users,OU=MyBusiness,DC=demo,DC=local";

Any ideas? 有任何想法吗? Do I need to open it up for "global" access somehow? 我是否需要以某种方式为“全局”访问打开它? If so, how would I go about doing that? 如果是这样,我将如何去做?

LDAP

I was able to successfully connect using another piece of software... 我能够使用其他软件成功连接...

LDAP

This is how we connect to our AD and it works great: 这是我们连接到广告的方式,并且效果很好:

<yourConfig>LDAP://ADServerName/OU=GROUPNAME,DC=domainName,DC=com</YourConfig>

And here is a sample code on how you can validate a user: 以下是有关如何验证用户的示例代码:

using (PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain,
                                                            ENTER YOUR DOMAIN NAME,
                                                            This is where the config that I mentioned above comes in,
                                                            ContextOptions.Negotiate,
                                                            ENTER YOUR AD SERVICE NAME,
                                                            ENTER YOUR AD PASSWORD))
            {
                UserPrincipal oUser = UserPrincipal.FindByIdentity(oPrincipalContext, THE USERNAME THAT YOU WANT TO VALIDATE);
                if (oUser != null)
                {
                    oADAcct = new CUserADAcct();
                    oADAcct.dumpAcctAttrs(oUser);
                }
            }

this is what you can try.. also are you sure that your DC=Demo and DC=Local those look like OU's to me 这是您可以尝试的方法..您还确定您的DC = Demo和DC = Local对我来说看起来像OU

const string Domain = "ServerAddress:389";
const string constrParts = @"OU=Users,DC=domain,DC=com";
const string Username = @"someusername";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Domain, constrParts);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext,  username);

暂无
暂无

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

相关问题 ASP.NET MVC-自动针对Active Directory验证用户身份吗? - ASP.NET MVC - Authenticate users against Active Directory automatically? asp.net上的活动目录用户 - active directory users on asp.net ASP.NET / IIS 7 - 使用Principal对Active Directory进行身份验证 - ASP.NET / IIS 7 - Authenticate against an Active Directory using a Principal 针对Active Directory组进行身份验证 - Authenticating against Active Directory Group ASP.NET / Active Directory-支持域用户自动登录 - ASP.NET / Active Directory - Supporting auto login for domain users ASP.NET Core使用Azure Active Directory进行身份验证,并跨请求保留自定义声明 - ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests 使用SQL Server中的配置文件对Active Directory进行ASP.NET MVC和WCF身份验证/授权 - ASP.NET MVC and WCF authentication/authorization against Active Directory with profiles in SQL server 如何在没有登录的情况下针对ASP.NET Core应用程序中的Active Directory组进行身份验证? - How do I authenticate against an Active Directory group in ASP.NET Core application without log in? 针对Active Directory的表单身份验证在IIS Express上有效,但在部署到IIS asp.net时出错 - Form authentication against active directory works on IIS Express but errors when deployed to IIS asp.net 按公司名称过滤 Active Directory 用户,Asp.net Core 2.1 - Filter Active Directory users by Company name, Asp.net Core 2.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM