[英]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?
如果是这样,我将如何去做?
I was able to successfully connect using another piece of software... 我能够使用其他软件成功连接...
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.