How to get username without domain

前端 未结 7 645
一整个雨季
一整个雨季 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.

提交回复
热议问题