Search code examples
asp.net-mvcgoogle-chromeasp.net-mvc-4impersonationiis-8.5

System.DirectoryServices.DirectoryServicesCOMException occurs only with Google Chrome


MVC application with ApplicationPoolIdentity on a remote IIS 8.5. Works fine with IE11 but when using Google Chrome, I get a yellow screen with System.DirectoryServices.DirectoryServicesCOMException

This is the code causing the error

 protected void Session_Start()
    {
        // Load current AD user
        UserPrincipal user = UserPrincipal.Current;
        Session.Add(name: "DisplayName", value: user.DisplayName);
        Session.Add(name: "AccountName", value: user.SamAccountName);
    }

Also in my Web.config file I have <identity impersonate="true" /> and <validation validateIntegratedModeConfiguration="false" /> that last bit is the only way I found to make things work. But it only works in IE.

Why is it working fine in IE11 but not in Chrome? What am I doing wrong?

UPDATE #1

I can make it work when using HostingEnvironment.Impersonate() to wrap every calls to Active Directory. But it still giving me a yellow screen when I try to alter an account in AD with user.Save()

System.UnauthorizedAccessException: Access denied.

I don't have full access to Active Directory Domain but I can reset password and enable/disable accounts in my OU.


Solution

  • https://stackoverflow.com/a/14545336/75172

    Using this class to wrap every calls to AD solved my problem.