Get User Name for NT Authentication in C#
December 10th, 2009 Posted in C#
Lots of systems sit behind an NT Authentication wall to keep the unwanted users out, but does it really do you any good if you don’t know which user made a given update to a system. Also this is good if you want to give a certain user administrative privledges, displaying certain functionality while hiding it from the rest of your users. The easiest way to get at that piece of information is to jump down into the System.Security.Principal.WindowsIdentity class and hit up the GetCurrent().Name method. Note this will pull back the user name preceeded by the domain they are logged onto so to ditch that you’ll just need to clean it up with a Regex statement (ex: Regex.Replace(sNTUser,”DOMAINNAME.”,”"))
