简体   繁体   中英

C# Get Windows User Display Name Error with UserPrincipal

I've been trying to get the display name of a user for an app I'm building. I worked on the accountmanagement.dll in my project and I'm using this code to grab the name:

string userFullName = UserPrincipal.Current.DisplayName;

The following error messages comes up in debug:

Unable to cast object of type

'System.DirectoryServices.AccountManagement.GroupPrincipal'

I'm obviously missing something but not sure about the next step. Any help would be appreciated.

This is a way to get the windows logged in user name when developing a web app:

string userFullName = Page.User.Identity.Name;

and web.config:

<system.web>
    <authentication mode="Windows"></authentication>
</system.web>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM