VB.Net - Identify User

This is the routine I use to identity the user accessing the application:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Public Shared Function NtUserNameNoWg() As String
Dim str As String = ""
Try
str = System.Web.HttpContext.Current.User.Identity.Name
Catch ex As Exception

End Try

If str = "" Then
str = System.Environment.UserName
End If

While InStr(str, "\") > 0
str = Mid(str, InStr(str, "\") + 1, 999)
End While
Return str
End Function

someone analizing the code recommended I use

1
WindowsIdentity.GetCurrent().Name

instead of

1
System.Web.HttpContext.Current.User.Identity.Name

See
https://stackoverflow.com/questions/33665929/whats-the-difference-between-system-environment-username-and-user-identity-name
for more information.