在MVC 4中获取客户端计算机名称 [英] Get client computer name in MVC 4

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

问题描述

下面的方法用于获取MVC 4中的客户端计算机名称.我注意到,对于某些客户端,它返回一个空字符串,为什么会发生这种情况?

The method below is used to get the client machine name in MVC 4. I've noticed that for some clients it returns an empty string, any idea why this could happen?

还有另一种更可靠的方式来获取客户端计算机名称吗?

Is there another,more reliable way to get the clients machine name?

private string GetWorkstation()
    {
        string ip = Request.UserHostName;
        IPAddress myIP = IPAddress.Parse(ip);
        IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
        List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
        return compName.First().ToUpper();
    }

推荐答案

为什么不尝试使用System.Net.Dns.GetHostName()

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

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