Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6758277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:45:52+00:00 2026-05-26T13:45:52+00:00

try to access an ldap server from an iis server in a dmz and

  • 0

try to access an ldap server from an iis server in a dmz and getting the error message : Information about the domain could not be retrieved (1355). There are articles about appending dns information or using the underlying objects, but these solutions are not working for me so please refrain from google searching and posting the same regurgitated bad advice.

I rewrote the entire layer to use principal objects. That got me a good error message at least.

using System;
using System.Collections;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Web;
using TheDomain.Common.Extensions;

namespace MobileApplications
{
    public class Ldap35: IDisposable
    {
        private string _ldapserver;
        private string _adminUser;
        private string _adminPassword;
        private PrincipalContext _connection;
        private UserPrincipal _userData;
        private IList<string> _groups;

    public delegate void MessagingHandler(string message);
    public event MessagingHandler Messaged;

    public Ldap35(string server, string adminuser, string adminpassword)
    {
        _ldapserver = server;
        _adminPassword = adminpassword;
        _adminUser = adminuser;
    }
    /// <summary>
    /// this will basically instantiate a UserPrincipal
    /// </summary>
    /// <param name="username">just the user</param>
    /// <param name="pass">just the password</param>
    /// <param name="domain">the correct domain, not sure if this is thedoamin.com or the_domain</param>
    /// <returns></returns>
    public bool Authenticate(string username, string pass, string domain)
    {
        if ( _connection == null)
            EstablishDirectoryConnection();

            ValidateConnection();
            if (!domain.IsEmpty() && !username.Contains("\\") && !username.Contains("/"))
                username = domain + "\\" + username;

            _userData = UserPrincipal.FindByIdentity(_connection, username);

            if (_userData == null)
                throw new ApplicationException("Unable to locate user.");

            if (! _connection.ValidateCredentials(username, pass))
                throw new ApplicationException("Invalid credentials.  Unable to log in.");

            //_userData = new UserPrincipal( _connection, username, pass, true );

            return true;
    }

    public bool Authenticate(string username, string pass)
    {
        return Authenticate(username, pass, "");
    }

    public bool IsMemeberOfGroup(string group)
    {
       ValidateConnection(); ValidateUser();
        return _userData.IsMemberOf(new GroupPrincipal(_connection));
    }

    public bool IsMemeberOfGroup(string group, bool caseSensitive)
    {
        if (caseSensitive)
            return IsMemeberOfGroup(group);

        GetGroups();

        return _groups.Any(g => g.ToLower().Trim() == group.ToLower().Trim());

    }

//        public IList<string> GetGroups()
//        {
//            if ( _groups == null )
//                _groups = new List<string>();
//
//            ValidateConnection(); ValidateUser();
//          
//                var results = _userData.GetGroups();
//
//                foreach (var principal in results)
//                {
//                    _groups.Add(principal.Name);
//                }
//         
//            return _groups;
//        }

    public IList<string> GetGroups()
    {
        if (_groups == null)
            _groups = new List<string>();

        ValidateConnection(); ValidateUser();
        Print("Getting groups");
        DirectoryEntry de = (DirectoryEntry)_userData.GetUnderlyingObject();
        object obGroups = de.Invoke("Groups");
        foreach (object ob in (IEnumerable)obGroups)
        {
            // Create object for each group.

            var obGpEntry = new DirectoryEntry(ob);
            Print(obGpEntry.Name);
            _groups.Add(obGpEntry.Name);
        }
        return _groups;
    }

    /// <summary>
    /// PrincipalContext class to establish a connection to the target directory and specify credentials for performing operations against the directory. This approach is similar to how you would go about establishing context with the DirectoryContext class in the ActiveDirectory namespace.
    /// </summary>
    /// <param name="adminuser">a user with permissions on the domain controller</param>
    /// <param name="adminpassword">the password to go with the above</param>
    /// <returns></returns>
    private void EstablishDirectoryConnection()
    {
        _connection = new PrincipalContext(ContextType.Domain, _ldapserver, "DC=thedomain,DC=com", ContextOptions.SimpleBind, _adminUser, _adminPassword);
    }

    private void Print(string message)
    {
        if (Messaged != null)
            Messaged(message);
    }

    private void ValidateConnection()
    {
        if ( _connection == null)
             throw new ApplicationException("No connection to server, please check credentials and configuration.");
    }

    private void ValidateUser()
    {
        if (_userData == null)
            throw new ApplicationException("User is not authenticated.  Please verify username and password.");
    }

    public void Dispose()
    {
        _userData.Dispose();
        _connection.Dispose();
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:45:52+00:00Added an answer on May 26, 2026 at 1:45 pm

    This article Active Directory – Adding a user to a group from a non domain-joined computer throws PrincipalException pointed me in the right direction. Although it really doesn’t make sense. I moved to a more modern approach than I posted above using the PrincipalObjects such as follows:

    var _connection = new PrincipalContext(ContextType.Domain, 
                                           _ldapserver, 
                                           "DC=domain,DC=com", 
                                           ContextOptions.SimpleBind, 
                                           _adminUser, 
                                           _adminPassword);
    var _userData = UserPrincipal.FindByIdentity(_connection, username);
    

    this allowed me to pass in the correct permissions to the domain controller, but then get groups method on the UserPrinicpal object was throwing the 1155 error.

    I resolved this by using the old method as follows. All works well now.

    DirectoryEntry de = (DirectoryEntry)_userData.GetUnderlyingObject();
    object obGroups = de.Invoke("Groups");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The error message I gen when I try to access the web page server
Im getting 500 internal server error everytime I try access my admin or login
I am getting the following error when I try to access bins private member
I keep getting a 404 Page Not Found whenever I try to access CodeIgniter's
I am getting this error when i try to access an asp website which
When I try to access info that is not presented in xml like so:
I keep getting compiler errors when I try to access flashVars in an AS3
I get this wired error only when I try to access the web page
I am getting the following error when trying to enumerate users in LDAP(Lightweight Directory
If I try to access this system variable from the Run... dialog, Windows tells

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.