Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# Rekursion zu tief? (StackOverflowException)

Empfohlene Antworten

Veröffentlicht

Hi zusammen,

um ein kleines AD Problem zu Lösen habe ich mir ein kleines Programm in C# gebaut.

Das Problem ist das ich beim Attribut MemberOF eines Users nur die Gruppen angezeigt bekomme denen der USer direkt zu geordnet ist. Da ich aber gerne auf seine Zuordnung durch Gruppen in Gruppen wissen möchte habe ich mir wie bereits erwähnt eine kleine Rekursion gebaut.

Diese nimmt eine Gruppe und sucht alle der Gruppe zugeordneten Gruppen und User. Jetzt zum eigentlichen Problem dieser Code:

	public class Group

	{

		public ArrayList Member;

		private string GroupName;

		private System.DirectoryServices.DirectoryEntry entryPC;

		private static NameTranslate nto;

		public Group (string name, System.DirectoryServices.DirectoryEntry entrypc)

		{

			this.GroupName=name;

			this.entryPC=entrypc;

			this.Member= new ArrayList();

			this.Member.AddRange(this.searchGroup(this.entryPC.Path, this.GroupName));

		}

		private ArrayList searchGroup(string LDAPPath, string GroupName)

		{

			ArrayList grouplst=new ArrayList();


			System.DirectoryServices.DirectorySearcher Searcher = new System.DirectoryServices.DirectorySearcher( LDAPPath  ); 

			if ( nto == null ) 

			{ 

				nto = new NameTranslate(); 

				nto.Init( System.Convert.ToInt32( ActiveDs.ADS_NAME_INITTYPE_ENUM.ADS_NAME_INITTYPE_GC ), "" ); 

			}

			Searcher.Filter = ( "(&(anr=" + GroupName+ ")(objectclass=group))" ); 


			Searcher.PropertiesToLoad.Add( "member" );

			Searcher.PageSize=int.MaxValue;

			Searcher.SizeLimit=int.MaxValue;




			SearchResultCollection SRColl = null; 

			try 

			{

				try

				{

					SRColl = Searcher.FindAll(); 

				}

				catch(Exception x)

				{

					Console.WriteLine(x.Message);

				}

				foreach(SearchResult resEnt in SRColl)

				{

					ResultPropertyCollection propcoll=resEnt.Properties;

					foreach(string key in propcoll.PropertyNames)

					{

						foreach(object values in propcoll[key])

						{

							grouplst.Add(values.ToString());


							string CN = values.ToString().Substring(values.ToString().IndexOf("CN=")+3,(values.ToString().Length-((values.ToString().IndexOf("CN=")+3)+( values.ToString().Length-values.ToString().IndexOf(",OU")))));

							if (!GroupName.ToUpper().Equals(CN.ToUpper()))

							{

								if (!(values.ToString().ToUpper().IndexOf("OU=BENUTZER")>=0))

								{

									grouplst.AddRange(searchGroup(LDAPPath,CN));

								}

							}

						}


					}

				}

			}

			catch(Exception e)

			{

				Console.WriteLine(e.Message);

			}

			return  grouplst;

		}

	}

erzeugt mir immer eine StackOverflowException.

Leider gibt es auch keine möglichkeit diese mit try catch abzufangen.

Hat jemand eine idee wie ich entweder mehr rekursionen hin bekomme oder eine alternative zur rekursion?

Schon mal Danke im Vorraus.

Hi nochmal sorry kann geschlossen werden.

hab die lösung selbst gefunden

hier der Code falls jemand mal sowas Braucht:

public class Group

	{

		public ArrayList Member;

		private string GroupName;

		private System.DirectoryServices.DirectoryEntry entryPC;

		private static NameTranslate nto;

		public Group (string name, System.DirectoryServices.DirectoryEntry entrypc)

		{

			this.GroupName=name;

			this.entryPC=entrypc;

			this.Member= new ArrayList();

			//this.Member.AddRange(this.searchGroup(this.entryPC.Path, this.GroupName));

			this.searchGroup(this.entryPC.Path, this.GroupName);

		}

		private void searchGroup(string LDAPPath, string GroupName)

		{


			ArrayList grouplst=new ArrayList();

			grouplst.Add(GroupName);

			for (int i = 0;i<grouplst.Count;i++)

			{


				System.DirectoryServices.DirectorySearcher Searcher = new System.DirectoryServices.DirectorySearcher( LDAPPath  ); 

				if ( nto == null ) 

				{ 

					nto = new NameTranslate(); 

					nto.Init( System.Convert.ToInt32( ActiveDs.ADS_NAME_INITTYPE_ENUM.ADS_NAME_INITTYPE_GC ), "" ); 

				}

				Searcher.Filter = "(anr=" + grouplst[i].ToString()+ ")"; 


				Searcher.PropertiesToLoad.Add( "member" );

				Searcher.PageSize=int.MaxValue;

				Searcher.SizeLimit=int.MaxValue;




				SearchResultCollection SRColl = null; 

				try 

				{

					try

					{

						SRColl = Searcher.FindAll(); 

					}

					catch(Exception x)

					{

						Console.WriteLine(x.Message);

					}

					foreach(SearchResult resEnt in SRColl)

					{

						ResultPropertyCollection propcoll=resEnt.Properties;

						foreach(string key in propcoll.PropertyNames)

						{

							foreach(object values in propcoll[key])

							{

								string CN = values.ToString().Substring(values.ToString().IndexOf("CN=")+3,(values.ToString().Length-((values.ToString().IndexOf("CN=")+3)+( values.ToString().Length-values.ToString().IndexOf(",OU")))));

								if (!GroupName.ToUpper().Equals(CN.ToUpper()))

								{

									if (!(values.ToString().ToUpper().IndexOf("OU=BENUTZER")>=0))

									{

										bool exist=false;

										for (int x=0;x<grouplst.Count;x++)

										{

											if (grouplst[x].ToString().ToUpper().Equals(CN.ToUpper()))

											{

												exist=true;

												x= grouplst.Count;

											}

										}

										if (!exist)

										{

											grouplst.Add(CN);

										}

									}

									else

									{

										this.Member.Add(values.ToString());

									}

								}

							}


						}

					}

				}

				catch(Exception e)

				{

					Console.WriteLine(e.Message);

				}

			}

		}

}

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.