Link to home
Start Free TrialLog in
Avatar of trevorhartman
trevorhartmanFlag for United States of America

asked on

getting the host name

Hello all,

I'm working on a asp.net application being used internally within our local network.  I need to get the Host Name of the station that is querying the aspx page.  I tried Request.UserHostName but that returns the IP address, identical to Request.UserHostAddress.

Any way to do this?

Thanks - Trevor
SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
erm its better to infringe on copyrights u say ?


anyhow trevorhartman,

you can use GetHostName with no parameters, this will return the host name of the local machine.

string strLocalHostName = Dns.GetHostName ();

look at the link in my post above for a fuller explanation and example c# code.
Avatar of trevorhartman

ASKER

thanks all, i ended up using:


                  string kioskHostIP = Request.UserHostAddress;
                  
                  // do a reverse lookup to figure the HostName using the IP address
                  IPHostEntry hostInfo = Dns.GetHostByAddress(kioskHostIP);
                  string kioskHostName = hostInfo.HostName;
                  Response.Write(kioskHostName + "<br>");

-Trevor
Heya,

did you try Request.UserHostName ?
or more apptly put...

Response.Write("The kiosk Host Name is " + Request.UserHostAddress);
grrrrrrr

Response.Write("The kiosk Host Name is " + Request.UserHostAddress);
SHOULD READ
Response.Write("The kiosk Host Name is " + Request.UserHostName);

for completeness
Response.Write("The kiosk Host Address is " + Request.UserHostAddress);
Yeah i tried that - from my first post:

" I tried Request.UserHostName but that returns the IP address, identical to Request.UserHostAddress. "

thx anyway

-Trevor
ah hah!.... hehe soz my mistake...

but therein i have more info on your problem...

Request.UserHostName - returns a string that contains the 'DNS' hostname...

DNS i hear u say!?

The problem you are having then is that the DNS server must be available and be able to resolve the client ip to a DNS name - if it cannot resolve it it returns the IP address as if you used Request.UserHostAddress.

so it seems theres a DNS resolution problem on your network.
could be, but this:

               string kioskHostIP = Request.UserHostAddress;
               
               // do a reverse lookup to figure the HostName using the IP address
               IPHostEntry hostInfo = Dns.GetHostByAddress(kioskHostIP);
               string kioskHostName = hostInfo.HostName;
               Response.Write(kioskHostName + "<br>");

works for me so i'm happy :)
sweet :) -- its a lesson i am yet to learn -- if it works it works :p