all groups > dotnet clr > january 2005 >
You're in the

dotnet clr

group:

calling ADSI from WebApp


calling ADSI from WebApp johnny
1/28/2005 1:13:02 AM
dotnet clr: Hello, I got this weird problem. I have an intranet application that needs to
communicate with Active directory. Authentication to Web application is done
by means of active directory accounts.

Now I have this code:

DirectoryEntry objDomain = new DirectoryEntry("LDAP://rootDse");
string domain = objDomain.Properties["defaultNamingContext"].Value.ToString();
DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry(string.Format("LDAP://{0}",domain));
ds.Filter = "(&(objectClass=group)(sAMAccountName=group_name))";
ds.SearchScope = SearchScope.Subtree;
SearchResult res = ds.FindOne();

When I run the application from any computer and authenticate as a user with
domain administrator privilige, everything works fine. When I authenticate as
a normal user application fail at line
SearchResult res = ds.FindOne();
throwing this exception:

Text: An operations error occurred
Exception Details: System.Runtime.InteropServices.COMException: An
operations error occurred
Stack Trace:
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +513
System.DirectoryServices.DirectoryEntry.Bind() +10
System.DirectoryServices.DirectoryEntry.get_AdsObject() +10
System.DirectoryServices.DirectorySearcher.FindAll(Boolean
findMoreThanOne) +198
System.DirectoryServices.DirectorySearcher.FindOne() +31

To remind: This bunch of code is called from a library that is inside GAC to
assert it's not consindered as partially trusted code.

I have no idea, where the problem could be. As a first thing I thought the
user doesn't have a privilige to communicate to AD, so I took this piece of
code and put it into a Windows application and run as a normal user. It
worked ok.

Can anybody have any idea what I should do? I'd be very grateful. Thanks in
advance.
Re: calling ADSI from WebApp Marc Scheuner [MVP ADSI]
1/28/2005 5:03:21 PM
[quoted text, click to view]

Post your question in a more "targeted" group, such as

mircosoft.public.adsi.general

or such - there are tons of excellent ADSI and ASP.NET gurus there to
answer your questions!

From my point of view, I'd say it's most likely a permissions issue
(almost always is, with ASP.NET).

Marc
================================================================
Marc Scheuner May The Source Be With You!
Re: calling ADSI from WebApp Willy Denoyette [MVP]
1/29/2005 3:01:32 PM
[quoted text, click to view]

Herewith some questions I like to be answered before I can help.

I assume you run this code from asp.net, right?
How do you authenticate and impersonate at the Web server (IIS asp.net I
assume),
more precisely, are you using "windows authentication" or something
else?
and, are you impersonating?
What version of IIS do you run (W2K or W2K3) and,
What is the asp.net identity used to run the worker process?
What is the anonymous account configured for IIS/ASP.NET? (domain or local
account)
Where is the DC located?
What exactly do you mean with:
When I run the application from any computer and authenticate as a user with
[quoted text, click to view]
do you mean when the client (browser or wathever) uses domain credentials it
works, and fails with it's local identity?
Note that when using windows authentication and impersonation at the Web
server, a client using it's domain account will impersonate the domain
account, but a local account (Workstation) will impersonate the anonymous
account when binding , this all provided Delegation is turned on for the web
server .



Willy.


Re: calling ADSI from WebApp Willy Denoyette [MVP]
1/29/2005 3:05:00 PM
Please note that you better cross post to microsoft.public.dotnet.framework
and a specialized adsi group (see Marc's reply).

Willy.


[quoted text, click to view]

Re: calling ADSI from WebApp Willy Denoyette [MVP]
1/29/2005 3:10:50 PM

[quoted text, click to view]

Marc, Johnny
Much better would be to cross-post [PS Johnny]to
microsoft.public.dotnet.framework and mircosoft.public.adsi.general
or microsoft.public.dotnet.framework.aspnet.security and
mircosoft.public.adsi.general
as the issue is .NET IIS/aspnet security and ADSI related .

Willy.
But don't multipost like you did.


AddThis Social Bookmark Button