Trouble using DirectorySearcher from a partially trusted contexthttp://forums.asp.net/t/897528.aspx/1?Trouble+using+DirectorySearcher+from+a+partially+trusted+contextTue, 28 Jun 2005 19:42:13 -0400897528971383http://forums.asp.net/p/897528/971383.aspx/1?Trouble+using+DirectorySearcher+from+a+partially+trusted+contextTrouble using DirectorySearcher from a partially trusted context <p>I have created a web application <font color="#000000">that</font> reads from the active directory (using a DirectorySearcher object) to populate certain field on the form. When I request the page from the browser on the machine where the web server is installed ,my code executes fine and the fields are populated correctly. The trouble is when I request the page using another machine, the web server returns a thrown exception ( Com execption) raised by&nbsp;either&nbsp;FindOne() or FindAll() method of the DirectorySearcher Object.<br> <br> Now, in my code, the DirectorySearcher is initiated and it's <font color="#0000ff"> SearchRoot</font> property is pointing to&nbsp;a <strong>DirectoryEntry</strong> object I initiated before, which defines the <font color="#0000ff">Path</font> property only ( no <font color="#0000ff">User</font> not <font color="#0000ff">Password</font> is used because I am using Windows authentication so I don't capture the user credentials apart from the username). Therefore the <strong>Searcher</strong> fails to log on to the AD to carry out the search. <br> In another scenario, I have supplied a valid user name and password for the DirectoryEntry object and the page was successfully returned to the user.<br> <br> My aim is to not use any hardcoded username/password in any file nor in&nbsp;the registry and I do want the user to log on via a logon page as I am using windows authentication.<br> <br> To summarise: Why DirectorySearcher successfuly logs on to the AD when the page is requested from the same machine as the web server, and fails to do so when the page is requested from another machine?<br> <br> <u>Notes to Add:<br> </u>I am using Windows Authentication and Impersonnation is set to true and also the <font size="2"><font face="Arial" color="#ff0000">AllowPartiallyTrustedCallersAttribute <font color="#000000">is emitted in my assembly. ( this was added in my Assembly.cs file and checked in the resulting assembly using idasm tool)<br> <br> Any help, comments would be highly appreciated.<br> <br> Thanks.<br> </font></font></p> </font> 2005-06-28T14:54:43-04:00971687http://forums.asp.net/p/897528/971687.aspx/1?Re+Trouble+using+DirectorySearcher+from+a+partially+trusted+contextRe: Trouble using DirectorySearcher from a partially trusted context <p>There is a new post now that discusses your options in this regard:<br> <br> <a href="/971665/ShowPost.aspx">http://forums.asp.net/971665/ShowPost.aspx</a><br> <br> See if this helps.&nbsp; If you have more questions, post back.</p> 2005-06-28T19:42:13-04:00