Home >Backend Development >C++ >How to Get the Computer Name and FQDN in .NET?

How to Get the Computer Name and FQDN in .NET?

Susan Sarandon
Susan SarandonOriginal
2024-12-28 09:19:11372browse

How to Get the Computer Name and FQDN in .NET?

Getting the Computer Name in .NET

Retrieving the computer name is a common task in .NET applications. There are several methods available to accomplish this, depending on the type of application you are developing.

  • Console or WinForms app:

    string computerName = System.Environment.MachineName;
  • Web app:

    string computerName = HttpContext.Current.Server.MachineName;
  • Getting the Fully Qualified Domain Name (FQDN):

    string fqdn = System.Net.Dns.GetHostName();

If System.Net.Dns.GetHostName() does not provide the FQDN and you require it, refer to this resource: [How to find FQDN of local machine in C#/.NET?](https://stackoverflow.com/questions/854213/how-to-find-fqdn-of-local-machine-in-c-net)

For additional insights, review this article: [Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName](https://codereview.stackexchange.com/questions/37366/difference-between-systeminformation-computername-environment-machinenam).

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

Statement:
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