For external users, the login Page is what I want. Credentials are verified against database.dbo.ta ble. Some of these users might not even be part of Active Directory. So that's fine. But for internal users, whom are part of Active Directory, I want to bypass login Page amd get username from Active Directory and go directly to process Application. How do I get that userName from Active directory. Everything I've tried comes up empty, unless I'm debugging from localhost. Thanks.
UserName through Active Directory(Internal) or LoginPage(External Users)
Collapse
X
-
Tags: None
-
.NET offers the System.Director yServices Namespace for working with Active Directory (making common tasks much simpler). Here's a short example (crude but simple) of authenticating a user against AD:
Hope that helps :)Code:public bool Authenticate(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(null == result) { return false; } //Update the new path to the user in the directory. _path = result.Path; _filterAttribute = (string)result.Properties["cn"][0]; } catch (Exception ex) { throw new Exception("Error authenticating user. " + ex.Message); } return true; }
Comment