I wrote a C# function that retries a list of users from Active Directory.
public static IEnumerable<string> ActiveDirectoryUsersList()
{
string[] adPropertiesToRetrive = { "displayName", "mail", "telephoneNumber", "displayName", "mobile" };
List<string> usersInfo = new List<string>();
// create and return new LDAP connection with desired settings
DirectoryEntry myLdapConnection = new DirectoryEntry("LDAP://OU=Users,OU=OUName,OU=Groups,DC=myDomain,DC=com", null, null, AuthenticationTypes.Secure);
DirectorySearcher search = new DirectorySearcher(myLdapConnection);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
foreach (var prop in adPropertiesToRetrive)
{
search.PropertiesToLoad.Add(prop);
}
SearchResultCollection allUsers = search.FindAll();
foreach (SearchResult user in allUsers)
{
foreach (var prop in adPropertiesToRetrive)
{
var val = user.Properties[prop].Count > 0 ? user.Properties[prop][0].ToString() : "-";
usersInfo.Add(val);
}
}
return usersInfo;
}
now I want to use this in my Razor function and iterate something like this:
@foreach (var user in Fucntion("Custom.ActiveDirectoryUsersList"))
{
@user
}
but the result of Function(string Name) is an HTML string result. How can i call upon the inline C# function defined to get the raw result of the function?