Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

Cannot gain accces to Active Directory from IIS ASP.net application but I Can from windows app

$
0
0

I have created a new ASP.net application and I am trying to get all members of ActiveDirectory but the code I have written is causing an exception once I publish to an IIS Server. It works on my local machine and installed IIS 7.5 but it doesn't work on our server, also I wrote a windows application (for test to connect to ActiveDirectory and get all members) running on the same server that works fine therefore i sure that is an IIS problem,

I'll post the code block and the exception here:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.DirectoryServices.DirectoryServicesCOMException (0x80072020): An operations error occurred.

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.PropertyValueCollection.PopulateList()
   at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
   at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
   at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
   at System.DirectoryServices.AccountManagement.PrincipalContext.ContextForType(Type t)
   at System.DirectoryServices.AccountManagement.Principal.set_SamAccountName(String value)
   at Sg.Portal.UserManagement.UI.InternalUserEdit.LoadData2(String userName) in d:\AppSrc\BuildSource\Alvand\CustomerPortalRelease\Sources\Source\Portal\UserManagement\UI\InternalUserEdit.aspx.cs:line 288
   at Sg.Portal.UserManagement.UI.InternalUserEdit.btnSelectUserName_Click(Object source, EventArgs args) in d:\AppSrc\BuildSource\Alvand\CustomerPortalRelease\Sources\Source\Portal\UserManagement\UI\InternalUserEdit.aspx.cs:line 271
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.usermanagement_ui_internaluseredit_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\d7bb0daf\afc65b68\App_Web_q5ivyzuq.11.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

my code is:

using (var ctx = new PrincipalContext(ContextType.Domain, AuthenticationHelper.DomainName))
			{
				var q = new UserPrincipal(ctx);
				q.Enabled = true;
				if (userName != "")
				{
					q.SamAccountName = userName + "*";
				}
				var users = new PrincipalSearcher(q).FindAll().OrderBy(x => x.SamAccountName).Take(201).ToList();
				msgThereAreMoreDomainUsers.Visible = users.Count > 200;
				lvwDomainUsers.DataSource = users;
				lvwDomainUsers.DataBind();
				updDomainUsers.Update();
			}



 


Viewing all articles
Browse latest Browse all 27852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>