How to capture a user's Active Directory userPrinicpalName
when they login with Windows authentication, and then compare that to a SQL Server table column in C#?
Any ideas would be much appreciated.
How to capture a user's Active Directory userPrinicpalName
when they login with Windows authentication, and then compare that to a SQL Server table column in C#?
Any ideas would be much appreciated.
Check out this page to get the Windows username: How do I get the current username in .NET using C#?
From there you would need to write a sql query that would look up the username.
cmd.CommandText = $"SELECT* FROM table WHERE columnName='{WindowsIdentity.GetCurrent().Name}'"
You may need additional using
statement to use WindowsIdentity. Add using System.Security.Principal
to where this method is being used.