Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Active directory

  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    34

    Active directory

    Salve. Sono Luigi, tempo fa avevo postato sul gruppo di Google ASP un problema sull'active directory:

    http://groups.google.it/group/it.com...e432f415d86502

    Ad oggi non sono riuscito ancora a risolvere il mio cruccio anche perchè mi sono focalizzato su un'altra pagina (sempre asp pura) che è più adatta al mio caso. L'esempio l'ho trovato qui:

    http://www.serverwatch.com/tutorials...le.php/1476961

    ma non riesco a farlo funzionare!!!
    Mi genera errore sulla riga (in testata quasi):

    Set oRootDSE = GetObject("LDAP://DC=myDC,DC=ORG")

    l'errore è: error '80072020'

    Dove sbaglio?
    Non c'è un sito dove poter scaricare un esempio funzionante in asp puro per ricavare la lista di utenti di ogni gruppo appartente al mio Active Directory?
    Anche in .NET andrebbe bene...

    Spero in qualche risposta.
    Grazie.

    Luigi.

  2. #2
    Utente di HTML.it L'avatar di albis
    Registrato dal
    May 2002
    Messaggi
    912
    tempo fà ho fatto qualcosa del genere in .net


    codice:
     
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.DirectoryServices;
    namespace INR.PrevisioniBudget
    {
    	/// <summary>
    	/// Summary description for LeggiUtenti.
    	/// </summary>
    	public class LeggiUtenti : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.Label lblDati;
    
    		
    		private void GetUsers(string strFiltro)
    		{
    			ArrayList users = new ArrayList();
    
    			// percorso AD, username e password per interrogare
    			string path = "LDAP://myDC.ORG/DC=myDC,DC=ORG";
    			
    			
    			string localUsername = "UtenteAutorizzato";
    			string localPassword = "PWDUtenteAutorizzato";
    
    			string strdistinguishedname = "";
    			string strname = "";
    			string struserprincipalname = "";
    			string strgivenname = "";
    			string strmemberof = "";
    			string strsamaccountname = "";
    			string strsn = "";
    			string strmail = "";
    			string strcn = "";
    			int x;
    
    
    			// effettuo una ricerca in ActiveDirectory
    			DirectorySearcher search = new DirectorySearcher(new DirectoryEntry(path, localUsername, localPassword));
    			search.Filter = "(&(objectclass=user)(objectCategory=person)" + strFiltro + ")"; // solo persone
     
    			// proprietà richieste
    			
    			search.PropertiesToLoad.Add("distinguishedname");
    			search.PropertiesToLoad.Add("name");
    			search.PropertiesToLoad.Add("givenname");
    			search.PropertiesToLoad.Add("memberof");
    			search.PropertiesToLoad.Add("samaccountname");
    			search.PropertiesToLoad.Add("sn");
    			search.PropertiesToLoad.Add("mail");
    			search.PropertiesToLoad.Add("cn");
    			
    			search.Sort.PropertyName="cn";
    
    			search.CacheResults = true;
    			search.SizeLimit = 1000; // massimo 1000 utenti
    			
    
    			// cerco gli utenti
    			SearchResultCollection results = search.FindAll();
    			//Response.Write(results.Count);
    			foreach(SearchResult result in results)
    			{
    				// aggiugno lo username alla collezione
    				strdistinguishedname="";
    				strname = "";
    				strgivenname = "";
    				strmemberof = "";
    				strsamaccountname = "";
    				strsn = "";
    				strmail = "";
    				strcn = "";
    
    				
    				try
    				{
    					strdistinguishedname = result.Properties["distinguishedname"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strname = result.Properties["name"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strgivenname = result.Properties["givenname"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strmemberof = result.Properties["memberof"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strsamaccountname = result.Properties["samaccountname"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strsn = result.Properties["sn"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strmail = result.Properties["mail"][0].ToString();
    				}
    				catch
    				{
    				}
    				try
    				{
    					strcn = result.Properties["cn"][0].ToString();
    				}
    				catch
    				{
    				}
    
    				/*
    				foreach(string propKey in result.Properties.PropertyNames)
    				{
    					
    					Response.Write("" + propKey + "=" + result.Properties[propKey][0].ToString() + "-|
    ");
    					//ResultPropertyValueCollection valcol = resEnt1.Properties[propKey];   
    				}
    				
    				*/
    				
    				lblDati.Text = lblDati.Text + "<tr>";
    				lblDati.Text = lblDati.Text + "<td>" + strdistinguishedname + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strname + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strgivenname + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strmemberof + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strsamaccountname + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strsn + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strmail + "</td>";
    				lblDati.Text = lblDati.Text + "<td>" + strcn + "</td>";
    				lblDati.Text = lblDati.Text + "</tr>";
    				
    			}
    			search.Dispose();
    
    			
    			
    			}
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			// Put user code to initialize the page here
    			int x;
    			
    			
    			lblDati.Text = lblDati.Text + "<table border=1>";
    			lblDati.Text = lblDati.Text + "<tr>";
    			lblDati.Text = lblDati.Text + "<td>strdistinguishedname</td>";
    			lblDati.Text = lblDati.Text + "<td>strname</td>";
    			lblDati.Text = lblDati.Text + "<td>strgivenname</td>";
    			lblDati.Text = lblDati.Text + "<td>strmemberof</td>";
    			lblDati.Text = lblDati.Text + "<td>strsamaccountname</td>";
    			lblDati.Text = lblDati.Text + "<td>strsn</td>";
    			lblDati.Text = lblDati.Text + "<td>strmail</td>";
    			lblDati.Text = lblDati.Text + "<td>strcn</td>";
    			lblDati.Text = lblDati.Text + "</tr>";
    			GetUsers("(CN<=e)");
    			GetUsers("(CN>=e)(CN<=n)");
    			GetUsers("(CN>=n)(CN<=s)");
    			GetUsers("(CN>=s)");
    			lblDati.Text = lblDati.Text + "</table>";
    			
    
    		}
    		#region Web Form Designer generated code
    		override protected void OnInit(EventArgs e)
    		{
    			//
    			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
    			//
    
    			InitializeComponent();
    			base.OnInit(e);
    		}
    		
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{    
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    		#endregion
    	}
    }
    probabilmente avevo preso spunto da qui
    http://www.aspitalia.com/script/705/...autenticazione
    Forza la magica ROMA

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    34
    Grazie infinite per l'attenzione (soprattutto ad un amico giallorosso... po popo popopopo ^_^).

    Il codice che mi segnali l'avevo trovato anche io da quel sito, ma il mio problema è capire come utilizzare asp.net... leggendo qua e là avendo iis 5 dovrei avere già il framework per utilizare asp.net... posso tranquillamente copiare questo codice, customizzarlo con i dati propri della mia rete e uploadarlo sul mio web server?!?

    La pagina dovrà avere estensione .aspx giusto?

    Luigi.

  4. #4
    Utente di HTML.it L'avatar di albis
    Registrato dal
    May 2002
    Messaggi
    912
    bo non ti so rispondere io utilizzo visualstudio .net
    e creo una solution nella intranet aziendale
    per publicare non so come si faccia

    prova ad andare nella sezione asp.net del forum
    Forza la magica ROMA

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    34
    Ah ok.. grazie mille.
    Luigi.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.