获取当前 Windows 用户 VB.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/754171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Current Windows User VB.net
提问by Andrew Parsons
I have tried multiple ways of grabbing the username of a current logged on user in vb.net/asp.net. I am running it on IIS 6 and understand that it will return NETWORK SERVICE for the username. I need to grab the username of the actual windows box log on.
我尝试了多种方法来获取 vb.net/asp.net 中当前登录用户的用户名。我在 IIS 6 上运行它并理解它将为用户名返回 NETWORK SERVICE。我需要获取实际 Windows 框登录的用户名。
I have tried the following code: Returns NT AUTHORITY\NETWORK SERVICE
我尝试了以下代码:返回 NT AUTHORITY\NETWORK SERVICE
Dim User = System.Security.Principal.WindowsIdentity.GetCurrent.User
Dim UserName = User.Translate(GetType(System.Security.Principal.NTAccount)).Value
Any help will be greatly appreciated. If I am unclear please let me know.
任何帮助将不胜感激。如果我不清楚,请告诉我。
回答by Mehrdad Afshari
You should set
你应该设置
<authentication mode="Windows" />
<identity impersonate="true" />
in Web.config
to be able to do that.
在Web.config
能够做到这一点。