I created a web system using C # and used a routine to authenticate the user by picking up the Active Directory user. But my system is not catching user AD: it is catching the user from the pool of the application. When I run the system locally on my machine the routine works perfectly, however when I upload the system to the server this problem happens.
The routine I use is this:
// Cria um contexto principal para definir a busca na base do AD.
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);
// Cria uma query do Active Directory Domain Services.
DirectorySearcher directorySearcher = new DirectorySearcher(principalContext.ConnectedServer);
// Cria um filtro para a busca com o login do usuário da rede.
directorySearcher.Filter = "(sAMAccountName=" + System.Environment.UserName + ")";
/*
* Cria um elemento da hierarquia do Active Directory.
* Este elemento é retornado durante uma busca através de DirectorySearcher.
*/
SearchResult searchResult = directorySearcher.FindOne();
// Cria um objeto encapsulado da hierarquia de diretório serviços do AD.
DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();
return directoryEntry.Properties["displayName"][0].ToString();
I'm using IIS 7.0.