Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 02, 2011 03:15 PM by shabirhakim1
Sep 02, 2011 02:29 PM|LINK
I asked this question in the C# group also since I do not know what forum to post this message to.
I have a C#.net 2008 desktop application that I modified to read the active directory to obtain what group(s) each user has access to. My company told me the windows and web applications should use the same logic when accessing the active directory. Since
the web application was completed first, I need to find a way to use the web method of accessing the active directory.
Thus I have the following questions about the desktop code listed below versus the web code listed below also:
1. Thus can you tell me if there is a way to use the web code in the windows version of accessing the active directory? If so, can you tell me how to modify the code so it would work in the windows application?
2. Is there a way to use at least part of the web code. If so, can you show me what code can be used?
3. If there is no way to use the web code and I should use the windows code that works, can you tell me why the web code would not work?
The following code is called from various portions of the desktop application. Right after the following class module returns from the application, the following line of code is executed in each section for the vatious groups that have been setup.
then do some process.
public class ActiveDirectoryUser
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
public class ActiveDirectoryValidator
private string _path;
private string _filterAttribute;
public ActiveDirectoryValidator(string path)
_path = path;
public bool IsAuthenticated(string domainName, string userName, string password)
string domainAndUsername = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, password);
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
SearchResult result = search.FindOne();
if (null == result)
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"];
catch (Exception ex)
throw new Exception(ex.Message);
Sep 02, 2011 03:15 PM|LINK
Your Company/Organization is very right that both windows as well as web uses is common way to access Active Directory . Interface used to access active directory info is called ADSI.
Yes,only difference will lie in how you are going to show information on the interface and fact is that that part you have to separate;like web controls are different from windows.
Anyways, I believe you can use 99% of web code in windows application except some portion which is about UI.
If you can mail me your web project( which is already developed);I will change that to windows version with one day