Question

I have MVC 4 web app deployed on 'Alpha' domain and web app is getting the Windows User details using the following code. We have trusted relationship between 3 different domains (Alpha, Beta and Gamma). When a user called Beta\bloggs login opens the web app following code returns the details of alpha\bloggs. Is there a way to get the right user from active directory.

Thanks in advance.

using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
    using (UserPrincipal user = UserPrincipal.FindByIdentity(context, username))
    {
        if (user != null)
        {
            HttpContext.Current.Session["FullUserName"] = fullName;
            HttpContext.Current.Session["EmailAddress"] = user.EmailAddress;
        }
    }
}
Was it helpful?

Solution

As far as I understand, you should test against a global catalog.

Can you try to change you context like this :

PrincipalContext context = new PrincipalContext(ContextType.Domain, "DNSName.Of.GlobalCatalog.com:3268", "DC=yourcompany,DC=com");

OTHER TIPS

Context.domain identifies the credential store to use. A connection to the correct domain would still be required to lookup information in another domain. Domain trust just specifies credential mapping, who in domain x maps to credential y in domain z.

I don't think that FindByIdentity can handle implicit domain trust lookups.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top