473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Attempting to validate id against Active Directory

Hi Folks,

I've got a intranet ASP.NET page that takes a user id (e.g. 'DoeJ') passed in and attempts to get the First and Last name of the user from the Active Directory. I'm running into some issues and am hoping someone can look at it and tell me whats wrong. I've gotten several different errors (Referal from server, unspecified error, etc). Any assistance would be greatly appreciated.

Best Regards,
Ted

CODE:
-----------------
DirectoryEntry _de = new DirectoryEntry( "LDAP://rootDSE" );
string _DomainPath = _de.Properties["DefaultNamingContext"][0].ToString();
DirectoryEntry _root = new DirectoryEntry( _DomainPath );
DirectorySearcher _src = new DirectorySearcher( _root);
_src.Filter = "(&(objectCategory=Person)(SAMAccountName=" + Request["DomainId"] + ")";

_src.PropertiesToLoad.Add( "givenname" );
_src.PropertiesToLoad.Add( "sn" );
_src.PropertiesToLoad.Add( "mail" );

SearchResult _res = _src.FindOne();

firstName = _res.Properties["givenname"][0].ToString();
lastName = _res.Properties["sn"][0].ToString();

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #1
2 1749
Ted,

Questions about AD are best posted in the microsoft.public.adsi.general
newsgroup where the two Joe's will be most help, but in answer to your
problem i think this should work

DirectoryEntry _root = new DirectoryEntry (@"LDAP://rootdse");
string path = _root.Invoke("GET","defaultNamingContext").ToStrin g();
DirectoryEntry _de = new DirectoryEntry ("LDAP://" + path);
DirectorySearcher _src = new DirectorySearcher( _de);
_src.Filter = "sAMAccountName=XXXXXXX";
_src.PropertiesToLoad.Add( "givenname" );
_src.PropertiesToLoad.Add( "sn" );
_src.PropertiesToLoad.Add( "mail" );
SearchResult _res = _src.FindOne();
firstName = _res.Properties["givenname"][0].ToString();
lastName = _res.Properties["sn"][0].ToString();
HTH

Ollie Riches

"Ted Vreeland via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:f3******************************@DotNetMonste r.com...
Hi Folks,

I've got a intranet ASP.NET page that takes a user id (e.g. 'DoeJ') passed in and attempts to get the First and Last name of the user from the Active
Directory. I'm running into some issues and am hoping someone can look at
it and tell me whats wrong. I've gotten several different errors (Referal
from server, unspecified error, etc). Any assistance would be greatly
appreciated.
Best Regards,
Ted

CODE:
-----------------
DirectoryEntry _de = new DirectoryEntry( "LDAP://rootDSE" );
string _DomainPath = _de.Properties["DefaultNamingContext"][0].ToString();
DirectoryEntry _root = new DirectoryEntry( _DomainPath );
DirectorySearcher _src = new DirectorySearcher( _root);
_src.Filter = "(&(objectCategory=Person)(SAMAccountName=" + Request["DomainId"] + ")";
_src.PropertiesToLoad.Add( "givenname" );
_src.PropertiesToLoad.Add( "sn" );
_src.PropertiesToLoad.Add( "mail" );

SearchResult _res = _src.FindOne();

firstName = _res.Properties["givenname"][0].ToString();
lastName = _res.Properties["sn"][0].ToString();

--
Message posted via http://www.dotnetmonster.com

Nov 16 '05 #2
I found the problem - I needed the <identity impersonate="true" /> setting added to the web.config - that allowed the AD query to run under the identity of the logged in user.

Thanks for the help anyway.

TV

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joeri KUMBRUCK | last post by:
Hello, I'm trying to create an ASP page where users can type in a username and password, and these credential should be checked with active directory. If username and password are correct, the...
3
by: Zeno Lee | last post by:
I'm trying to authenticate a user against a windows network. I want it to work across any kind of windows network from NT 4.0 up to Windows 2003 ADS. So far I've been using DirectoryEntry and...
5
by: Bud | last post by:
I would like to be able to pass a request to IIS to have a user name and password authenticated against my Active Directory Users database. I'm running Server 2003 however my web pages are build...
2
by: Steffen Balslev | last post by:
I tried to find a way to validate user credentials using C#, searching google and lots of other news and kb sites left me without a solution. You can use a SSPI but it's that easy to implement so...
3
by: GC | last post by:
I'm looking to build a web app that authenticates against my current active directory. Anyone have any examples on how to do this? Thanks!
0
by: Joeri KUMBRUCK | last post by:
Hello, I'm trying to create an ASP page where users can type in a username and password, and these credential should be checked with active directory. If username and password are correct, the...
4
by: Scott Lezberg \(Deltek\) | last post by:
Does anyone have some sample code that can validate a domain username and password account to check to see if it is a valid account? Thanks in advance. Scott
3
by: Greg | last post by:
I am trying to figure out how to validate a userid against AD. At the time the user will be logged on as the local admin, right after puuling down a fresh image. the form asks for the userid and...
2
by: rote | last post by:
My sceanrio is this on an asp.net 2.0 freamework. I want to use any of the data controls e.g Gridview,DetailView etc.. But i want some buttons e.g update,edit save etc to be enable or disabled...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.