I am using Environment.UserName to get the UserName in .net , but Iam getting Machine name instead of UserName. Also I tried using System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); and even this returning Machine name instead of UserName. Any idea?
A:
Try this (found on http://www.developerfusion.com/code/4409/get-current-username-in-vbnet)
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer
Public Function GetUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(" "), 50)
iReturn = GetUserName(userName, 50)
GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function
MaQleod
2010-08-30 17:46:10
Thanks for the reply.. :)I got it .Actually Iam trying to get the UserName in Dotnetnuke.DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().Username; solved my issue.Thanks again.
Divya
2010-08-31 11:21:15