0

I've already tried these methods:

  • System.Net.Dns.GetHostName
  • Environment.MachineName
  • My.Computer.Name
  • Environ$("computername")

Each returns APPDEV, which I assume is the name of the server hosting my web page.
I've even asked friends to try my page with these methods and they see the same thing.
How can I get it to return the PC name entered at initial setup, like Joseph-PC?

Joseph Webber
  • 2,010
  • 1
  • 19
  • 38

2 Answers2

1

Since the browser won't tell the computer name to the server, a web page is (thankfully) not able to know your computer's name.

fero
  • 6,050
  • 1
  • 33
  • 56
  • Ah, so I was on a hopeless quest then. Oh well, it would have been cool otherwise. – Joseph Webber Feb 20 '14 at 07:26
  • On a web page like a company intranet, you might be able to find out the computer's name by using the method Markus suggested. But over the internet, this is hardly possible. – fero Feb 20 '14 at 07:28
0

You can try HttpContext.Current.Request.UserHostName. Similarly, UserHostAddress retrieves the IP of the client. But this information might not be valid in most circumstances due to (legitimate) privacy or network (NAT, Proxies, ...) reasons. So I wouldn't rely to strong on the presence or validity of the data.

If you are provided an IP address in UserHostName, you can use System.Net.Dns.GetHostEntry to make a DNS reverse lookup to find the name. This also might not work under all circumstances as not every client is registered at a DNS server.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • `HttpContext.Current.Request.UserHostName` returns the IP, not the PC name. Thanks anyway. – Joseph Webber Feb 20 '14 at 07:30
  • @JosephWebber: as I wrote, don't rely on the validity of the information. You can still try to make a reverse lookup to get the name. I've updated the answer. – Markus Feb 20 '14 at 07:40