PC Review


Reply
Thread Tools Rate Thread

DirectorySearcher works locally in VS2005 but not on webserver

 
 
Jason Wilson
Guest
Posts: n/a
 
      30th Jan 2007
I have written a web app in ASP.NET that works fine in VS2005, but
DirectorySearcher fails when I copy it to the web server.

Here's some code:

Dim sUser As String = Environment.UserName
Dim adEntry As New DirectoryEntry("LDAP://
DC=radnet,DC=ausrad,DC=com")
Dim adSearcher As New DirectorySearcher(adEntry)
adSearcher.SearchScope = SearchScope.Subtree
adSearcher.Filter = "(&(objectCategory=person)
(objectClass=user)(sAMAccountName=" & sUser & "))"
adSearcher.PropertiesToLoad.Add("mail")

adSearcher.PropertiesToLoad.Add("extensionAttribute1") 'This
contains employee SSN
Dim adResult As SearchResult = adSearcher.FindOne
***hfUserEmail.Value =
adResult.GetDirectoryEntry().Properties("mail").Value
***hfUserSSN.Value =
adResult.GetDirectoryEntry().Properties("extensionAttribute1").Value

*** These 2 lines give me: Object reference not set to an instance of
an object. (nullreference exception)

I've tried adding credentials to the DirectoryEntry with the same
results.

Thanks in advance,

Jason Wuksib

 
Reply With Quote
 
 
 
 
KA Kueh
Guest
Posts: n/a
 
      31st Jan 2007
Hi,

My guess is that the webserver is not a member of the domain that it is
querying. This will cause the query to fail.

Regards,
Kueh.

"Jason Wilson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have written a web app in ASP.NET that works fine in VS2005, but
> DirectorySearcher fails when I copy it to the web server.
>
> Here's some code:
>
> Dim sUser As String = Environment.UserName
> Dim adEntry As New DirectoryEntry("LDAP://
> DC=radnet,DC=ausrad,DC=com")
> Dim adSearcher As New DirectorySearcher(adEntry)
> adSearcher.SearchScope = SearchScope.Subtree
> adSearcher.Filter = "(&(objectCategory=person)
> (objectClass=user)(sAMAccountName=" & sUser & "))"
> adSearcher.PropertiesToLoad.Add("mail")
>
> adSearcher.PropertiesToLoad.Add("extensionAttribute1") 'This
> contains employee SSN
> Dim adResult As SearchResult = adSearcher.FindOne
> ***hfUserEmail.Value =
> adResult.GetDirectoryEntry().Properties("mail").Value
> ***hfUserSSN.Value =
> adResult.GetDirectoryEntry().Properties("extensionAttribute1").Value
>
> *** These 2 lines give me: Object reference not set to an instance of
> an object. (nullreference exception)
>
> I've tried adding credentials to the DirectoryEntry with the same
> results.
>
> Thanks in advance,
>
> Jason Wuksib
>



 
Reply With Quote
 
Jason Wilson
Guest
Posts: n/a
 
      31st Jan 2007
It's an intranet server and is a member of the domain. Also if it was
a security issue I think that I would get an access denied exception

 
Reply With Quote
 
Jason Wilson
Guest
Posts: n/a
 
      31st Jan 2007
Just a thought, but I am expecting the webserver to the do the query
under the context of the user of the web page. Do I need to do
something to make this happen? I mean do I need to somehow turn
impersonation on?

Jason


 
Reply With Quote
 
Jason Wilson
Guest
Posts: n/a
 
      31st Jan 2007
That was it. I added:

<identity impersonate="true" userName="domain\user" password="*****"/>

And now it works. It was running under the local system account
before which didn't have necessary rights (you'd think you'd get an
exception, but no).

I tried just turning on impersonation without providing credentials
and it failed because Kerberos doesn't like the 2 hop token. I think
you can get around that with enabling the webserver for delegation in
AD, but that gets kind of messy. This will work for now.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Works Locally in VS2005 but not on Web schmeckel Microsoft ASP .NET 9 4th Apr 2007 04:54 AM
How to change local webserver in VS2005? =?Utf-8?B?RGF2ZQ==?= Microsoft ASP .NET 3 23rd Mar 2007 07:48 PM
In vs2005 how to debug under IIS and not VS WebServer WT Microsoft ASP .NET 1 31st May 2006 06:39 AM
.NET application exported from Access works locally but not on webserver. Andy Microsoft ASP .NET 1 11th Jul 2005 03:45 PM
How PagedSearching works with DirectorySearcher Randy Bradley Microsoft Windows 2000 Active Directory 1 9th Apr 2004 07:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 PM.