Remove domain information from login id in C#

后端 未结 8 2480
谎友^
谎友^ 2021-02-12 12:02

I would like to remove the domain/computer information from a login id in C#. So, I would like to make either \"Domain\\me\" or \"Domain\\me\" just \"me\". I could always chec

8条回答
  •  梦如初夏
    2021-02-12 12:22

    I always do it this way:

        string[] domainuser;
        string Auth_User = Request.ServerVariables["AUTH_USER"].ToString().ToLower(); 
        domainuser = Auth_User.Split('\\');
    

    Now you can look at domainuser.Length to see how many parts are there and domainuser[0] for the domain and domainuser[1] for the username.

提交回复
热议问题