0

I'm trying to get the userName of the connected user in my application but the System.Net.CredentialCache.DefaultNetworkCredentials.UserName is always empty.

Someone can suggest me how i can do to get it with this method ?

var ClientCredential =  System.Net.CredentialCache.DefaultNetworkCredentials;
Console.writeLine("UserName : " +  ClientCredential.UserName);
DIF
  • 2,470
  • 6
  • 35
  • 49
K. BLEU
  • 291
  • 1
  • 4
  • 9
  • What do you mean by "connected user"? Do you mean the Windows user running the application? – Martin Costello Apr 17 '14 at 09:32
  • I mean the user connected on my application – K. BLEU Apr 17 '14 at 09:37
  • http://stackoverflow.com/a/1240379/242520 http://msdn.microsoft.com/en-us/library/system.environment.username.aspx and more links are just a quick Google away... http://stackoverflow.com/q/6747263/242520 Look another one... – ta.speot.is Apr 17 '14 at 09:41
  • 1
    "Connected" is a very vague term given the little information you've provided as to what, if anything, the user is connected *to*. – Martin Costello Apr 17 '14 at 09:56
  • 1
    If you can't explain what does 'connected' mean, then at least tell us what is your application based on? WinForms? WPF? ASP.NET? ASP MVC? WCF? Silverlight? RIA? other? – quetzalcoatl Apr 17 '14 at 10:00

1 Answers1

3

On the assumption you're using the term "connected" to mean "What is the Windows user name of the person running the application", the answer is to use the Environment.UserName property.

Martin Costello
  • 9,672
  • 5
  • 60
  • 72