确定客户端的计算机名称 [英] Determine Client's Computer Name

查看:129
本文介绍了确定客户端的计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个内部网站,将显示基于计算机的名称,因为不同的计算机是在不同的地区不同的列表,有没有办法(控制器或模型中),以确定客户端的计算机名称?

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 controller or model) to determine the client's computer name?

我已经试过system.environment.machinename但只返回服务器的名称,任何其他的想法?

I have tried system.environment.machinename but that only returns the name of the server, any other ideas?

推荐答案

我得到它的工作使用以下内容:

I got it working using the following:

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

从compnamehelper code:

code from compnamehelper:

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

这篇关于确定客户端的计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆