Wednesday, 31 January 2018

c# - How can I get a pc's user name?




I'm trying the get the user's name [ex) admin, John, Lucy, etc.] so I can store it to a string and create a file path to save files in my application. I have absolutely no idea how to do this. I tried using the Microsoft.AspNet.Identity; namespace but that didn't help me any, as the UserManager class item is templated to take a User, which is what I'm trying to find in the first place. I'm honestly just walking through the forest at night right now. Can't see and no idea where to go. Any help would be awesome!! Thanks


Answer



Try this to get the username of the currently logged on user:



string username = Environment.UserName;



Microsoft Docs



This is in the system namespace, so there's no need to use Windows Identity.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...