我有一個在我們的Intranet上運行的ASP.NET應用程序。在生產中,我可以從域上下文獲取用戶,並可以訪問許多信息,包括他們的名字和姓氏(UserPrincipal.GivenName和UserPrincipal.Surname)。從機器上下文獲取用戶全名
我們的測試環境不是生產域的一部分,測試用戶在測試環境中沒有域帳戶。所以,我們將它們添加爲本地機器用戶。當他們瀏覽到開始頁面時,系統會提示他們輸入憑據。我用下面的方法來獲取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;
}
我這裏的問題是,當UserPrinicipal被retrived當ContextType ==機我沒有得到這樣給定名稱或姓名性能。有沒有辦法在創建用戶時設置這些值(Windows Server 2008)還是需要以其他方式來解決這個問題?