Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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:

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


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900