A cloud-based identity and access management service for securing user authentication and resource access
Getting UPN from wpf application
I have an WPF application which needs to get the User principal Name to do some authentications.
I am using .Net core 3.1 .
How can I do it ?
I have tried using System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName;
but this always throws exception of type
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.
Source=System.DirectoryServices.AccountManagement
StackTrace:
at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)
at System.DirectoryServices.AccountManagement.UserPrincipal.get_Current()
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.