get UserName without the 20 char Limit

前端 未结 1 1764
醉梦人生
醉梦人生 2021-01-28 20:26

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 Sys         


        
相关标签:
1条回答
  • 2021-01-28 20:44

    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

    0 讨论(0)
提交回复
热议问题