Home >Backend Development >C++ >How to Get a Computer's Name and FQDN in .NET?
Retrieving the Computer Name in .NET
Obtaining the computer name is a common operation in .NET applications. Depending on the application type, you can use different techniques to retrieve this information.
Console or WinForms Applications:
For console applications or Windows Forms applications, you can use the System.Environment.MachineName property, which returns the NETBIOS computer name. The code below demonstrates its usage:
string computerName = System.Environment.MachineName;
Web Applications:
In ASP.NET web applications, you can access the computer name through the HttpContext.Current.Server.MachineName property. This property retrieves the server name from the request context.
string computerName = HttpContext.Current.Server.MachineName;
Fully Qualified Domain Name (FQDN):
If you need to obtain the fully qualified domain name (FQDN) of the computer, you can use the System.Net.Dns.GetHostName() method.
string fqdn = System.Net.Dns.GetHostName();
Additional Considerations:
The above is the detailed content of How to Get a Computer's Name and FQDN in .NET?. For more information, please follow other related articles on the PHP Chinese website!