get UserName without the 20 char Limit

五迷三道 提交于 2019-12-02 20:02:45

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/38378739/get-username-without-the-20-char-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!