【发布时间】:2014-06-04 21:41:14
【问题描述】:
在他们登录网站或自动获得访问权限后,我需要帮助来检索当前用户的姓名,因为他们使用 asp.net 4.0(最好是 vb)登录到域上的计算机
我尝试了以下调用
HttpContext.Current.Profile.UserName
HttpContext.Current.User.Identity.Name
但他们只是返回空白。
我没有使用 Active Directory 的经验,而且我发现的大部分内容都假设程序想要读取、写入和更新目录服务。
更新我现在已经尝试了
Dim id As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim User As WindowsPrincipal = New WindowsPrincipal(id)
Return User.Identity.Name
它返回我的名字为 IIS APPPOOL\ASP.NET V4.0
更新 2
Environment.UserName.ToString()
返回 ASP.NETv4.0
我也变了
在 web.config 中设置为 true,它将 NT AUTHORITY\USR 作为当前用户返回,这与我根据我的搜索所期望的一致。我仍然不确定为什么当 impersonate=false 时系统返回 asp.net apppool 而不是用户名。
【问题讨论】:
标签: asp.net active-directory user-profile