Saturday, March 24, 2012

Operations error

I'm trying in ASP.NET web page load user accounts from active directory.
When I'm developing on local web server it works.
I'm using authentication mode=windows and identity impersonate=true
When I put page and DLL on server I get COMException. I try to run it on
Win2000 server and Win2003 server and I get the same results (COMException)

Can anyone help ?

Server Error in '/ADSearchNtsrvprnTest' Application.
------------------------

An operations error occurred
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: An
operations error occurred

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x80072020): An operations error occurred]
System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail) +705
System.DirectoryServices.DirectoryEntry.Bind() +10
System.DirectoryServices.DirectoryEntry.get_AdsObj ect() +10
System.DirectoryServices.DirectorySearcher.FindAll (Boolean
findMoreThanOne) +199
System.DirectoryServices.DirectorySearcher.FindOne () +31
ADSearchNtsrvprnTest.WebForm1.GetAllUsersInfo1(Str ing Root) in
\\ntsrvprn\wwwroot$\adsearchntsrvprntest\webform1. aspx.cs:76
ADSearchNtsrvprnTest.WebForm1.Page_Load(Object sender, EventArgs e) in
\\ntsrvprn\wwwroot$\adsearchntsrvprntest\webform1. aspx.cs:29
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +739

------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032Debug and determine exactly what line is throwing the exception
Can you post the actual code that is generating the error?
"jeff" <yupyup@.yup.com> wrote in message
news:cde143a7e8f84a719928607719f1116d@.ureader.com. ..
> Can you post the actual code that is generating the error?

Here is full code:

using System;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.DirectoryServices;

namespace ADSearchWebTest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
UserInfo1[] arr;
arr = GetAllUsersInfo1("DC=MyDomain,DC=com");
string strFormat = "{0};{1};{2}";
for (int Index=0; Index < arr.Length; Index++)
{
Response.Write(string.Format(strFormat, arr[Index].ID,
arr[Index].CeleMeno, arr[Index].OsC));
}
}
}

//----------------------------------
private static string GetDefaultADRoot()
{
DirectoryEntry objDE = new DirectoryEntry("LDAP://rootDSE");
string strReturn =
objDE.Properties["defaultNamingContext"].Value.ToString();
objDE.Close();
return strReturn;
}

//----------------------------------
public static UserInfo1[] GetAllUsersInfo1(string Root)
{
string strRoot;
if (Root != null)
{
if (Root.Length > 256)
throw new ArgumentOutOfRangeException("Root");
strRoot = Root;
}
else
strRoot = GetDefaultADRoot();
DirectoryEntry RootEntry = new DirectoryEntry("LDAP://" + strRoot);

DirectorySearcher mySearcher =
new DirectorySearcher(RootEntry,
"(&(objectCategory=person)(objectClass=user))",
new string[] {"objectGUID", "displayName", "EmployeeID"},
SearchScope.Subtree);
mySearcher.PageSize = 500;
SearchResultCollection srcResult = mySearcher.FindAll();
//RootEntry.Close();
if (srcResult.Count > 0)
{
UserInfo1[] arrReturn = new UserInfo1[srcResult.Count];
for (int Index=0; Index < srcResult.Count; Index++)
{
arrReturn[Index] = new UserInfo1();
arrReturn[Index].ID =
GetLDAPGUIDString((byte[])srcResult[Index].Properties["objectGUID"][0]);
if (srcResult[Index].Properties["displayName"] != null)
arrReturn[Index].CeleMeno =
srcResult[Index].Properties["displayName"][0].ToString();
if (srcResult[Index].Properties["EmployeeID"] != null)
arrReturn[Index].OsC =
srcResult[Index].Properties["EmployeeID"][0].ToString();
}
srcResult.Dispose();
mySearcher.Dispose();
return arrReturn;
}
else
return null;
}

//----------------------------------
private static string GetLDAPGUIDString(byte[] arrGiud)
{
StringBuilder sbuGuid = new StringBuilder(32);
string strFormat = "{0:X2}";
foreach (byte bByte in arrGiud)
sbuGuid.AppendFormat(strFormat, bByte);
return sbuGuid.ToString();
}
//----------------------------------
public class UserInfo1 : IComparable
{
public string ID, CeleMeno, OsC;

public int CompareTo(object obj)
{
if(obj is UserInfo1)
{
UserInfo1 objUI = (UserInfo1) obj;
return string.Compare(CeleMeno, objUI.CeleMeno, true);
}
throw new ArgumentException("Object is not UserInfo1");
}
}
//-----------------------------------
}
}
That is all the code. Show "only" the code that is generating the error.
"sirfunusa" <sirfunusa@.hotmail.com> wrote in message
news:1143743843.806090.292570@.i39g2000cwa.googlegr oups.com...
> That is all the code. Show "only" the code that is generating the error.

DirectoryEntry RootEntry = new DirectoryEntry("LDAP://" + strRoot);

DirectorySearcher mySearcher = new DirectorySearcher(RootEntry,
"(&(objectCategory=person)(objectClass=user))",
new string[] {"objectGUID", "displayName", "EmployeeID"},
SearchScope.Subtree);
Turn on Basic Authentication on the server. It's a permissions issue.
Locally you are using NT Auth, but that doesn't work across computer
boundries.

Yes, you'll get the user popup.

0 comments:

Post a Comment