How to get username without domain

前端 未结 7 620
一整个雨季
一整个雨季 2021-02-06 21:12

In an aspx page I get the Windows username with the function Request.LogonUserIdentity.Name. This function returns a string in the format \"domain\\user\".

相关标签:
7条回答
  • 2021-02-06 21:47

    An alternative way of doing the same thing as the other answers:

    var usernameWithoutDomain = Path.GetFileName(@"somedomain\someusername")
    

    It is just unsafe as not checking for the @ variant of usernames.

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