【发布时间】:2013-10-10 10:42:12
【问题描述】:
我想知道这是否可能或可能的解决方法。我想让我的网站在 IIS 中运行 - 运行该网站的应用程序池将是一个可以查找 AD 的服务帐户。
要获取当前的 App Pool 帐户并设置 Principal 上下文,我有以下内容:
string appPoolAccount = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Define Context
PrincipalContext context = new PrincipalContext(ContextType.Domain);
现在用户将在自己的机器上运行该站点 - 当他们在那里启动浏览器时,启动该进程的用户名将是“test123”作为示例 - 因为这将是登录用户。
我需要得到的是他们正在运行浏览器的用户 ID,这样我就可以执行以下操作(第二个参数是否是运行我找到的进程的用户的字符串):
UserPrincipal user = UserPrincipal.FindByIdentity(context , 'test123');
到目前为止,我已尝试从以下位置获取该用户字符串:
string test = Environment.UserName; //Took the App Pool Account
WindowsIdentity wi = WindowsIdentity.GetCurrent(); // Took App Pool account
string test = HttpContext.Current.User.Identity.Name; //bombed out as null
【问题讨论】:
-
它是一个什么样的应用程序? ASP.NET? WCF 还是其他?
HttpContext.Current.User在非请求处理线程上调用会变成null,这很正常。
标签: c# .net authentication iis active-directory