C# Get Currently logged in windows user


using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Security.Principal; /* Namespace needed to get currently logged in user */
 
namespace SecurityModules
{
    [TestClass]
    public class Security
    {
 
        [TestMethod]
        public void GetCurrentUser()
        {
            // Act
            var currentlyLoggedInUser = WindowsIdentity.GetCurrent().Name;
 
            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(currentlyLoggedInUser));
        }
    }
}

Comments

Popular posts from this blog

WPF How to Dispose ViewModel when the associated UserControl (Not Window) closes?

C# How to unit test Dispatcher

WPF: How to Deep Copy WPF object (e.g. UIElement) ?