0

Trying to get the local machine name for an Azure hosted ASP application.

Request.ServerVariables["HOST_NAME"] 

returns 127.0.0.1 as does HOST_ADDRESS

In fact I can't find anything in Request.Server variables that reflects the local hostname.

Dns.GetHostEntry(Request.UserHostAddress).HostName 

will not work as this is a server side lookup, so all you get is the public gateway name not the actual end-user machine name.

Any ideas?

I am stumped and just feel this should be so simple!??!

Jezbers
  • 815
  • 10
  • 20
  • Would `Environment.MachineName` work for you - http://msdn.microsoft.com/en-us/library/system.environment.machinename%28v=vs.110%29.aspx? – Gaurav Mantri Nov 29 '14 at 17:39
  • Thanks Gaurav, just testing that one now... – Jezbers Nov 29 '14 at 17:58
  • Sadly not. Returns the server name. – Jezbers Nov 29 '14 at 18:06
  • 1
    Sorry, I think I misunderstand your question. Do you want to find the name of end user's computer who is using your application? – Gaurav Mantri Nov 29 '14 at 18:08
  • Yes, that is correct – Jezbers Nov 29 '14 at 18:10
  • 1
    I don't think it would be possible. I just did a quick search and found these links: http://community.discountasp.net/threads/client-user-and-computer-name-in-asp-net.14191/, http://stackoverflow.com/questions/9923575/get-computer-name. HTH. – Gaurav Mantri Nov 29 '14 at 18:17
  • Thanks Gaurav, I have done similar searches and seen similar comments. It seems "security risk" seems to be spouted, although the actual risk of someone knowing your NetBIOS name is beyond me. If your firewall is OK then knowing your NetBIOS name should make no difference. Equally I questions what exactly is the point of Request.ServerVariables["HOST_NAME"]. It seems to me this call serves no purpose. Perhaps just obsolete. – Jezbers Nov 29 '14 at 18:21
  • I guess I need to add an Active X component but this still seems huge overkill. – Jezbers Nov 29 '14 at 18:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65881/discussion-between-gaurav-mantri-and-jezbers). – Gaurav Mantri Nov 29 '14 at 18:23
  • You're right. May be suited for Intranet applications. – Gaurav Mantri Nov 29 '14 at 18:24

1 Answers1

1

As you're potentially behind a load balancer when you deploy to azure try using

Request.ServerVariables["REMOTE_ADDR"]
Code Uniquely
  • 6,356
  • 4
  • 30
  • 40