IIS configuration to authenticate using Active Directory

Asked

Viewed 533 times

3

I created a web system using C# and use a routine to authenticate the user by taking the Active Directory user. However my system is not getting the AD user: it is catching the user from pool of the application. When I run the system locally on my machine the routine works perfectly, but when I move 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 OSI 7.0.

  • The AD authentication method is installed on the server runs IIS?

  • Yes, @Andremesquita , I think the problem may be in the IIS configuration, you know how to configure IIS to authenticate with the AD user?

  • 1

    If the application is ASP.NET MVC, it would not just be the case to use <authentication mode="Windows" /> in the web.config? Why you need to check the Active Directory directory directory?

  • 2

    See if this answer helps you. It also has a link on how to set up IIS for this type of authentication.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.