Akrem
Akrem

Reputation: 4652

get UserName without the 20 char Limit

I have to read the user log in my app even with run as and the name created in domain in windows server 2012have 23 char, i used :

Environment.UserName


new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;

System.Security.Principal.WindowsIdentity.GetCurrent().Name

but all this give me the name without the 3 last char I used :

UserPrincipal.Current.UserPrincipalName
UserPrincipal.Current.Name

but give me the displayed name

how can i get the full length login name

Upvotes: 0

Views: 714

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27332

This is a hard limit on the samAccountName property:

"You can't modify the length of the user's samAccountName, it is a defined value within the schema and is set to 20."

See: this page for source

Maybe you could try the UserPrincipalname

System.DirectoryServices.AccountManagement.UserPrincipal.Current().UserPrincipalName

you need to add a reference to the AccountManagement Namespace

Upvotes: 1

Related Questions