Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want client machine name where the ASP.Net web application is running.

I am using below code:
C#
var hostEntry = Dns.GetHostEntry(Request.UserHostAddress);
          Response.Write("machinename=" + hostEntry.HostName);


Its working Offline but not working on online server.

It shows this error:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: No such host is known

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SocketException (0x2af9): No such host is known]
   System.Net.Dns.GetAddrInfo(String name) +471
   System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6, Boolean throwOnFailure) +125
   System.Net.Dns.GetHostEntry(String hostNameOrAddress) +5390027
   Web.TestMachineName.GetMachineName() +282
   Web.TestMachineName.Page_Load(Object sender, EventArgs e) +5
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Posted
Updated 16-Jan-17 22:47pm
v2

Hi. What is the solution for this?
 
Share this answer
 
MSDN says: If the host name could not be found, the SocketException exception is returned with a value of 11001 (Windows Sockets error WSAHOST_NOT_FOUND). This exception can be returned if the DNS server does not respond. This exception can also be returned if the name is not an official host name or alias, or it cannot be found in the database(s) being queried.

Details here: MSDN: Dns.GetHostEntry Method (String)[^]
So, make sure that the known issues/scenarios are properly handled.

Further, try GetHostByName instead of GetHostEntry, source here[^].
 
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