Asp.net Error Obtaining Group Names
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up LDAP get group names up vote 0 down vote favorite I am getting "Logon failure: unknown user name or bad password" error when I try to get the groups a user belongs to. User authentication works fine and this is what I can't understand. How can I properly authenticate a user against AD but can't get his group names? I get user's ID and password. I have a class that deals with authentication. if ((true == adAuth.IsAuthenticated(sDomain, sID, sPassword))) { string sGroups = adAuth.GetGroups(); This is the authentication class: public class LdapAuthentication { string _path; string _filterAttribute; public LdapAuthentication(string path) { _path = path; } public bool IsAuthenticated(string domain, string username, string pwd) { string domainAndUsername = domain + "\\" + username; DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd); 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 ((result == null)) { return false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = Convert.ToString(result.Properties["cn"][0]); } catch (Exception ex) { throw new Exception("Error authenticating user. " + ex.Message); //return false; } return true; } public string GetGroups() { //DirectorySearcher search = new DirectorySearcher
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 3 of 3 Thread: [RESOLVED] Error authenticating. Error obtaining group names. Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch http://stackoverflow.com/questions/16282143/ldap-get-group-names to Hybrid Mode Switch to Threaded Mode Jan 4th, 2006,12:29 PM #1 Anddmx View Profile View Forum Posts Thread Starter Member Join Date Jun 2005 Posts 52 [RESOLVED] Error authenticating. Error obtaining group names. Hi, Iam using form authentication against active directory. Everything compiles just fine with no errors but when I try to login I http://www.vbforums.com/showthread.php?379586-RESOLVED-Error-authenticating-Error-obtaining-group-names get this Error.(Error authenticating. Error obtaining group names. The specified domain either does not exist or could not be contacted) I have no clue what would cause this problem. Any Suggestions? I can post code if you need to see it. thanks Reply With Quote Jan 4th, 2006,01:55 PM #2 mendhak View Profile View Forum Posts Visit Homepage ASP.NET Moderator Join Date Feb 2002 Location Ulaan Baator GooGoo: Frog Posts 38,174 Re: Error authenticating. Error obtaining group names. Show code. Mendhak.com|Flickr|Github|GPS Logger for Android| Reply With Quote Jan 4th, 2006,02:05 PM #3 Anddmx View Profile View Forum Posts Thread Starter Member Join Date Jun 2005 Posts 52 Re: Error authenticating. Error obtaining group names. I figured it out. Forgot to uncheck Enable anonymous access. Thanks Reply With Quote Quick Navigation ASP.NET Top Site Areas Settings Private Messages Subscriptions Who's Online Search Forums Forums Home Forums Visual Basic Visual Basic .NET VB.net CodeBank Visual Basic 6 and Earlier CodeBank - Visual Basic 6 and earlier Modern Windows Ex
to AD itself, so when you try to build a DirectoryEntry to use as your SearchRoot for the DirectorySearcher, the bind fails. You http://www.derkeiler.com/Newsgroups/microsoft.public.dotnet.framework.aspnet.security/2007-01/msg00076.html could get around this by supplying the same credentials you used for the DirectoryEntry for the authenticate function in the GetGroups function. An even simpler idea would be to combine http://www.justskins.com/forums/problems-when-authenticating-against-64348.html both of them together and just add memberOf to PropertiesToLoad for the initial DirectorySearcher. That said, I hate this KB article and have commented many times on its lack asp.net error of quality. The technique they show for authentication does not scale and does not work with multiple domains and does more than just verify the credentials, which is all an authentication function should do. Their group extraction code is naive and misses nested groups while including non-security (distribution) groups. I've suggested numerous better ways to do this stuff asp.net error obtaining in previous newsgroup posts and have written about a bunch of these topics in my book as well. I also recommend using the AD membership provider in .NET 2.0, if necessary adding in an LDAP-based role provider. Joe K. -- Joe Kaplan-MS MVP Directory Services Programming Co-author of "The .NET Developer's Guide to Directory Services Programming" http://www.directoryprogramming.net -- "Kevin Humphreys"
using Forms Authentication and Visual Basic .NET Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET - ASP.NET Security I have recently followed the doent to allow authentication against Active Directory using Forms authentication as described in the the Microsoft Knowledge Base Article 326340 ([url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340[/url]) I can authenticate correctly, but when I attempt to retrieve the groups for the user I get the following error Object reference not set to an instance of an object I have changed the code slightly to pull back the properties I have access to for the user but memberOf is not listed Have I missed something, or is there some AD configuration needed to expose this The code I'm working with is below ... Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode March 1st,11:01 AM #1 Problems when authenticating against the Active Directory using Forms Authentication and Visual Basic .NET I have recently followed the doent to allow authentication against Active Directory using Forms authentication as described in the the Microsoft Knowledge Base Article 326340 ([url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;326340[/url]) I can authenticate correctly, but when I attempt to retrieve the groups for the user I get the following error Object reference not set to an instance of an object I have changed the code slightly to pull back the properties I have access to for the user but memberOf is not listed Have I missed something, or is there some AD configuration needed to expose this The code I'm working with is below I hope someone can assist me with this Thanks in advance Paul Eas Publi