问题
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