更新
因此,有些用户可以使用它,有些用户则不能。当我通过IE7使用自己的帐户时,它不起作用(我的代码捕获了异常,并退回到只使用标识名而不是AD全名)。当我通过Chrome浏览器尝试时,它会提示我输入我提供的用户名和密码,并显示全名。因此,用户帐户、服务器代码和设置是相同的,但使用不同的浏览器发送身份验证可以使其正常工作。
你好,
string domainUser = filterContext.HttpContext.User.Identity.Name;
WindowsIdentity windowsIdentity = filterContext.HttpContext.User.Identity as WindowsIdentity;
WindowsImpersonationContext impersonationContext = windowsIdentity.Impersonate();
DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domainUser.Replace('\\', '/') + ",User");
filterContext.Controller.ViewData["User"] = (string)userEntry.Properties["fullname"].Value;
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
</authorization>
<identity impersonate="false"/>
WindowsImpersonationContext impersonationContext = windowsIdentity.Impersonate();
最后一点是,这似乎只是在应用程序的新部署(从测试到上线)时才开始发生的。我不知道我是否缺少IIS设置或什么,但代码没有更改。
谢谢。