如何在MVC4或javascript中获取主机名? [英] How can i get hostname in MVC4 or javascript?

查看:56
本文介绍了如何在MVC4或javascript中获取主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用MVC4来构建报告。现在我有一个问题想问你。

我构建这个问题并将其公开到IIS中。根据客户需求,他们需要控制有多少用户登录才能看到网络报告以及他们想要看到的内容:PC名称或设备名称IP地址和赢取用户。其中有一点,(重要的是) PC名称或设备名称)。我不知道如何获得这些信息。所以有人知道如何使用MVC或javascript获取电脑名称或设备名称吗?



谢谢



TONY

Hi Everyone,

I'm using MVC4 to build report. Now i have one problem want to ask you.
i build this problem and public it into IIS. coz of customer requirement, they need to control how many of user have logged in to see web report and what they want to see are : PC Name or Device Name IP Address and Win User.Among of those points, there is 1 important point ( PC Name or Device Name). I don't know how to get that info. so does anybody know how to get pc name or device name by using MVC or javascript?

Thanks

TONY

推荐答案

Javascript不提供开箱即用的库。即使你使用扩展,你也会在客户端获得IP,这不一定有用(例如,在家里,我的机器有IP 102.168.0.2,但这是我的网络上的IP地址和许多其他用户在他们自己的网络上将拥有相同的IP。如果您在没有网络的网络上(即IP是唯一的,在内联网上可能就是这种情况),这不是一个问题。 />


您更有可能想要服务器上的请求IP。在控制器上这些将证明是有用的:



Javascript doesn't provide a library out-the-box. Even if you use extensions, you'd get the IP at the client, which isn't necessarily useful (e.g. At home my machine has IP 102.168.0.2, but this is the IP address on my network, and many other users will have the same IP on their own network. This isn't such a problem if you are on a network without aub-nets (i.e. the IPs are unique, which may be the case on an intranet.

More likely you want the IP of the request at the server. On the controller these will prove useful:

var foo = Request.UserHostName;
var bar = Request.UserHostAddress;





IIRC,您必须进行故障转移,因此如果未解析UserHostName,您将推迟到UserHostAddress。请注意,即使这会导致问题:假设我的家庭网络上有两台设备(192.168.1.2和192.168.1.3),我们通过公共宽带路由器访问您的站点,我们b它们显示为相同的地址。更糟糕的是,我的家庭路由器的地址如果过期可能会改变,因为两个设备的内部地址可能类似,所以即使这些IP也不一定足够。



这个问题的一个常见解决方案是提供一个带有GUID的跟踪cookie,并将请求IP和会话GUID存储在一起,尽管你将再次拥有用户删除cookie或禁用cookie时出现问题。



IIRC, you have to fail over, so if the UserHostName isn't resolved you defer to the UserHostAddress. Note that even this causes problems: Let's say there are two devices on my home network (192.168.1.2 and 192.168.1.3), we access your site via our common broadband router, we both appear as the same address. Worse my home router's address might change if it expires, as might similarly the internal addresses of the two devices so even these IPs are not necessarily enough.

A common solution to this problem is to provide a tracking cookie with a GUID and storing the request IP and the session GUID alongside eachother, though again you are going to have problems if the user deletes their cookies or disables them.


这篇关于如何在MVC4或javascript中获取主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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