.NET Framework Bookmark and Share   
 index > .NET Base Class Library > System.Interopservices.COMException while tring to get the group in which the logged in user belongs to and iterate through the result
 

System.Interopservices.COMException while tring to get the group in which the logged in user belongs to and iterate through the result

My application is a website build in Asp.net 2.0 framework.I have used Windows authentication.

When the user log in I am trying to take all the groups in which the user is a "member of".
I am using System.DirectoryServices.AccountManagement dll for achievin g the same.



One user(only one)is not able to access the application.For all other usrs its working fine..when the user tries to access the appln getting an UNknown error and ASP.ner default error page gets displayed.

Exception of type:System.Interopservices.COMException

Also the errorcode of the COM exceptionI receive is:

ErrorCode:20497

Symbol: S_ADS_ERRORSOCCURRED

Description :One or more errors occurred

Source:System.Directoryservices...

While hosting in my system's IIS its working fine(hardcoded the username)...when the same code is deployed in development/production server ...the xception occurs.....

I am using the following code to retrieve the groups of the user from AD:

public

static List<User> GetActiveDirGroups(string domainId)

PrincipalContext objPC = new PrincipalContext(ContextType.Domain);

UserPrincipal objUserPrincipal = UserPrincipal.FindByIdentity(objPC, domainId);

List<User> groupUsers = new List<User>();

lock (objUserPrincipal)

PrincipalSearchResult<Principal> memGroups = objUserPrincipal.GetGroups();

if (!memGroups.Equals(null))

{

groupUsers = GetActivedirectory(memGroups, groupUsers, objPC);

}

The user is having 267 groups...then I am trying to iterate through this collection using code...

public static List<User> GetActivedirectory(PrincipalSearchResult<Principal> groups, List<User> groupUsers, PrincipalContext objPC)

IDisposable disposable;

int i = 0;

IEnumerator<Principal> iPrincipal = groups.GetEnumerator(); try

{

while (iPrincipal.MoveNext())

Principal objPrinciple = iPrincipal.Current; User grpUser = new User();

groupUsers.Add(grpUser);

}

}

catch (Exception ex)

{
throw ex;

}

return groupUsers;

}

Also Please note :
When I try to debug through the code hardcoding the user name I am able to login,but when I deployed the same code in development server it is throwing this exception.

Please help me to resolve the same.

  • Moved byeryangMSFTWednesday, September 23, 2009 6:38 AM (From:.NET Base Class Library)
  •  
Dhanya V

Hi,
Could you provide more details about the exception? set a breakpoint at the catch exception block, press F5 to run your web application, login with that user, then you get the breakpoint hit, paste the exception here, it will be helpful for further investigation.

Thanks,
Eric


Please remember to mark helpful replies as answers and unmark them if they provide no help.
eryang
Hi Eric, Thanks For looking into it.....The twist of this issue is that when you debug the code hardcoding as the user no exception is caught and I was able to login to the application as the user. But when i deploy the same code (hardcoding the username) in development server it shows default asp error page and the detail of the exception is : Unknown error (0x5011) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Unknown error (0x5011) Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [COMException (0x5011): Unknown error (0x5011)] _Default.GetCurrentUser() +2534 _Default.Page_Load(Object sender, EventArgs e) +24 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Dhanya V

wouldyou provide more detail on the GetCurrentUser method?


kashif
Kpbutt
Hi,
It's likely to get quicker and better responses to ASP.NET issues at http://forums.asp.net where ASP.NET experts live in, good luck!

Thanks,
Eric

Please remember to mark helpful replies as answers and unmark them if they provide no help.
eryang

You can use google to search for other answers

Custom Search

More Threads

• Help with FileSystemWatcher
• RSA Encryption Problem
• System.Console and external processes
• intellisense for contained words, how about unknown words?
• How to get the DomainSid or domain Sid ?
• Print word document to specific try
• Memory Leak due to EndInvoke
• Timer - in W98 fails, in WinXP OK
• First Chance Exception With Deserialization????
• Different levels in configuration section