Home > Backend Development > C++ > How to Retrieve the Computer Name in .NET?

How to Retrieve the Computer Name in .NET?

Linda Hamilton
Release: 2024-12-31 15:21:13
Original
1018 people have browsed it

How to Retrieve the Computer Name in .NET?

Retrieving Computer Name in .NET

In the .NET programming framework, there are several methods to retrieve the name of the computer on which an application is running.

Console or WinForms Application

For console or WinForms applications, you can use the System.Environment.MachineName property:

string computerName = System.Environment.MachineName;
Copy after login

Web Application

For web applications, you can access the computer name through the HttpContext.Current.Server object:

string computerName = HttpContext.Current.Server.MachineName;
Copy after login

Fully Qualified Domain Name (FQDN)

If you need the fully qualified domain name (FQDN) instead of the short name, use the System.Net.Dns.GetHostName() method:

string fqdn = System.Net.Dns.GetHostName();
Copy after login

Additional Considerations

FQDN Resolution:

If System.Net.Dns.GetHostName() does not return the FQDN, refer to the question "How to find FQDN of local machine in C#/.NET?" for additional details.

Property Differences:

For more information on the differences between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName, refer to the documentation "Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName".

The above is the detailed content of How to Retrieve the Computer Name in .NET?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template