0

Our Application is using .Net Web API which is running on IIS 8. For past few days exactly 8 AM(i.e.. the time user starts to access the application) we are getting the below exception while trying the get the User Identity. It's works after App Pool Refresh and till next day we don't see any exception. Can someone help me on this.

System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
   at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
   at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
   at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue)
   at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)

Code :

using (var user = UserPrincipal.FindByIdentity(UserPrincipal.Current.Context, IdentityType.SamAccountName, userName) ??

                              UserPrincipal.FindByIdentity(UserPrincipal.Current.Context, IdentityType.UserPrincipalName, userName))

            {
                return user == null ? null : new WindowsIdentity(user.UserPrincipalName);
            }
Max_dev
  • 508
  • 7
  • 25
  • related: https://stackoverflow.com/questions/1722398/error-0x80005000-and-directoryservices – Daniel A. White Oct 02 '19 at 15:28
  • Thanks Daniel. It works perfectly during the day, we are getting exception only when it access on start of day. As I mentioned it works after app pool recycle – Max_dev Oct 02 '19 at 15:34
  • Could you share some sample code? an under which idenity your application pool is running? You could try to set the application pool identity as a network service you can find this setting in the iis application pool advance setting. Change the application pool setting Load User Profile to "True" [image](https://imgur.com/a/ebLJJJE) – Jalpa Panchal Oct 04 '19 at 05:57
  • Hi, I am running the app pool under service account identity . I can't change that to network service as i need it to connect to database. Do we need the change the load profile to "True" for service account? I thought it should be for individual account.. ( updated with code) – Max_dev Oct 04 '19 at 10:33
  • you need to set a load profile to "True" in iis application pool advance setting. you refer this [link](https://social.msdn.microsoft.com/Forums/vstudio/en-US/dafc2e1e-bbd8-49b2-990d-f17502c86291/active-directory-error-unknown-error-0x80005000?forum=csharpgeneral) – Jalpa Panchal Oct 07 '19 at 03:19
  • @Max_dev is your issue resolved? – Jalpa Panchal Oct 14 '19 at 05:52
  • Nope.. It's occurring randomly and and when it happen we see high memory usage on the server. couldn't find the exact reason why this happen? The same code works fine in another load balanced server with similar IIS settings. – Max_dev Oct 15 '19 at 03:49
  • did you try to set the load profile to "True" in iis application pool advance setting? also refer this [link](https://blogs.msdn.microsoft.com/dsadsi/2009/08/28/getting-an-exception-the-specified-directory-service-attribute-or-value-does-not-exist-when-you-try-to-search-a-user-in-an-ad-container-using-system-directoryservices-accountmanagement/) – Jalpa Panchal Oct 15 '19 at 07:02
  • It doesn't worked.. We increased the memory on the server and the issue is not occurring now. – Max_dev Oct 27 '19 at 02:55

0 Answers0