如何在C#Web APP中获取当前的Windows登录名? [英] How to get current Windows Login Name in C# Web APP?
问题描述
如何获取Windows登录名?我使用了以下方法:
How can I get the user name of Windows Login? I used these methods:
- Environment.UserName
- WindowsIdentity.GetCurrent().Name;
但是,当我将其放在IIS服务器中时,它将使用服务器的名称,而不是我的计算机的名称.
But, when I PUT this inside IIS server, it takes the name of the server, not my machine.
推荐答案
尝试 Page.User.Identity.Name
.这应该是您要寻找的.此属性是从 HttpContext
派生的,表示当前HTTP请求的已登录用户安全信息.
Try Page.User.Identity.Name
. This should be what you're looking for. This property is derived from HttpContext
and represents the logged in user security information for the current HTTP request.
如果结果为空,那么我怀疑IIS设置没有正确配置.尝试以下链接中的建议:
If the result is null, then I would suspect that the IIS settings is not configured properly. Try the advice in the following links:
http://forums.asp.net/t/1689878.aspx/1
HttpContext.Current.User.Identity.Name为空
这篇关于如何在C#Web APP中获取当前的Windows登录名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!