calling ADSI objects from WebApplication

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default calling ADSI objects from WebApplication

    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(Boole an throwIfFail) +513
    System.DirectoryServices.DirectoryEntry.Bind() +10
    System.DirectoryServices.DirectoryEntry.get_AdsObj ect() +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.
    johnny Guest

  2. Similar Questions and Discussions

    1. Webapplication Login and RSA API
      Hallo, wie have an RSA ACE Server. I must implement RSA check by loging into webapplication (ASP.NET) . which api (and which RSA Agent) should I...
    2. webapplication with SQL-server
      Hi, I'm new to ASP. Currently I'm planning to develop a web application for my company. I want to use ASP for the application and use SQL-server...
    3. convert to dll in vb.net (webapplication)
      Hello I need to know which files in .net framework could help me make dll files, I make a library class project and I want to convert it to dll to...
    4. Calling in child objects with 'me'
      I'm having some problems understanding the use of "me" in child objects. When I create and instance of the child object and I want to access a...
    5. calling adsi from aspnet
      We have an aspnet app that allows the user to change their password. We are using windows authentication on win2003. In the sample code below the...
  3. #2

    Default Re: calling ADSI objects from WebApplication

    It is a problem related to security context. Is your application set to
    impersonate? Is it II5 or IIS6? What is the value of
    System.Security.Principal.WindowsIdentity.GetCurre nt().Name? Is that a
    domain account?

    One thing you can do to check this issue really quickly is add a domain name
    or server to your binding strings, LDAP://mydomain.com/rootdse for example,
    and specify credentials for your directory entry objects. If that fixes the
    problem, then it is definitely an issue with your security context.

    There is a good article here that discusses potential remedies and this
    problem has been discussed to death in this another other groups, so Google
    should help you find some more info.

    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;329986[/url]

    Joe K.

    "johnny" <johnny@discussions.microsoft.com> wrote in message
    news:64FDE7AF-4174-4D70-AE19-AA7EC00DB649@microsoft.com...
    > 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(Boole an throwIfFail) +513
    > System.DirectoryServices.DirectoryEntry.Bind() +10
    > System.DirectoryServices.DirectoryEntry.get_AdsObj ect() +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.

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139