Get Current Windows User VB.net

戏子无情 提交于 2019-12-24 05:11:13

问题


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.

I have tried the following code: Returns 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.


回答1:


You should set

 <authentication mode="Windows" />
 <identity impersonate="true" />

in Web.config to be able to do that.



来源:https://stackoverflow.com/questions/754171/get-current-windows-user-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!