Determine Client's Computer Name

后端 未结 7 658
情歌与酒
情歌与酒 2020-11-29 23:41

I am building an intranet site that will display different lists based on the computer name because different computers are in different areas, is there a way (within a cont

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 00:29

    I got it working using the following:

    string IP = Request.UserHostName;
    string compName = CompNameHelper.DetermineCompName(IP);
    

    code from compnamehelper:

    public static string DetermineCompName(string IP)
    {
        IPAddress myIP = IPAddress.Parse(IP);
        IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
        List compName = GetIPHost.HostName.ToString().Split('.').ToList();
        return compName.First();
    }
    

提交回复
热议问题