User1016820894 posted
I am using VS 2019 and building a aspx web page that will retrieve information on the use account from directory services (see code below.
I am getting an error on the red lines below: The type or namespace name 'DirectoryEntry' could not be found (are you missing a using directive or an assembly reference?).
I have the namespace for Systrem.Directoryservices in the code so I am not sure why I am getting the error.
Code:
<%@ Page Language="C#" %>
<%@Import Namespace="System"%>;
<%@Import Namespace="System.Configuration"%>;
<%@Import Namespace="System.Collections"%>;
<%@Import Namespace="System.DirectoryServices"%>;
<%@Import Namespace="System.DirectoryServices.AccountManagement"%>;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
userid = GetHTTPContext();
GetADGroups(userid);
public SortedList GetADGroups(string loginName)
{
List<string> userNestedMembership = new List<string>();
if (string.IsNullOrEmpty(loginName))
throw new ArgumentException("The loginName should not be empty");
SortedList ADGroups = new SortedList();
int backSlash = loginName.IndexOf("\\");
string userName = backSlash > 0 ? loginName.Substring(backSlash + 1) : loginName;
DirectoryEntry domainConnection = new DirectoryEntry();
domainConnection.AuthenticationType =
System.DirectoryServices.AuthenticationTypes.Secure;
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://xxxdomain");
DirectorySearcher samSearcher = new DirectorySearcher(directoryEntry);
samSearcher.SearchRoot = domainConnection;
}