I have and ASP.NET application that runs on our intranet. In production I can get the user from the domain context and have access to lots of information including their first and last name (UserPrincipal.Givename and UserPrincipal.Surname).
Our test environment is not part of the production domain and test users do not have domain accounts in the test environment. So, we add them as local machine users. They are prompted for credentials when they browse to the start page. I use the following method to get the UserPrincipal
public static UserPrincipal GetCurrentUser()
{
UserPrincipal up = null;
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
up = UserPrincipal.FindByIdentity(context, User.Identity.Name);
}
if (up == null)
{
using (PrincipalContext context = new PrincipalContext(ContextType.Machine))
{
up = UserPrincipal.FindByIdentity(context, User.Identity.Name);
}
}
return up;
}
The problem I have here is that when the UserPrinicipal is retrived when ContextType == Machine I do not get properties like GivenName or Surname. Is there a way to set these values when creating the user (Windows Server 2008) or do I need to go about this in a different way?