Get value of custom attribute for user in Active Directory
<p>I am trying to read the values of a few custom attributes that have been added inside Active Directory but I can't find anything that explains how to do this. I have found a page that helped me make the connection and find the user and this allows me to read some of the pre-made attributes but it did not cover how to read custom attributes. Searching on Google/SO all I find are outdated instrutions that use <code>DirectoryEntry</code> which appears to have been dropped in the later .Net released. I say this since Visual Studio has no idea what that object is or what namespace it belongs to.</p>

<p>Can anyone tell me how I am supposed to read custom attributes?</p>

<pre><code>using System.DirectoryServices.AccountManagement;
using System.Web.Mvc;

namespace JobSight.WebUI.Controllers
{
    public class BaseController : Controller
    {
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            UpdateUserFromAD();
        }

        private void UpdateUserFromAD()
        {
                var Context = new PrincipalContext(ContextType.Domain, "DomainController");
                var UserData = UserPrincipal.FindByIdentity(Context, User.Identity.Name);
        }
    }
}
</code></pre>